当前位置:编程学习 > C#/ASP.NET >>

进程间通信的问题

MemoryMappedFile.CreateOrOpen("name", FileSize); 我用这个方法创建的内存映射管理。现在的问题是,如果我两个应用程序的名称不一样,就会提示找不到"name";如果两个应用程序的名称一致,则无任何问题。这是为什么啊? --------------------编程问答--------------------
引用 楼主 tyl023 的回复:
这是为什么啊?


如果两个程序的名称不一样,就相当于地址不一至
这两个程序去不同的地址找数据,当然报错了
解决方法,随便搞一个串:wsfvsafwerwfsdfvsdfafsafsafasfsfas

--------------------编程问答-------------------- 进程间通信得两个应用程序名称一致? --------------------编程问答--------------------
引用 2 楼 tyl023 的回复:
进程间通信得两个应用程序名称一致?


和应用程序名无关的
和CreateOrOpen的第一个参数有关
CreateOrOpen第一个参数你不要使用程序名

--------------------编程问答--------------------  MemoryMappedFile.CreateOrOpen("111111", FileSize);  应用程序的名称是不一样的,还是不可以啊。 --------------------编程问答-------------------- using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO.MemoryMappedFiles;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Formatters.Binary;
using System.IO;

namespace WindowsFormsApplication7
{
    public partial class Form1 : Form
    {
        private MemoryMappedFile memoryFile = null;
        private MemoryMappedViewStream stream = null;
        private const int FileSize = 1024 * 1024 * 10;
        public Form1()
        {
            InitializeComponent();
            InitMemoryMappedFile();
        }
        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                IFormatter formatter = new BinaryFormatter();
                stream.Seek(0, SeekOrigin.Begin);
                MyPic obj = formatter.Deserialize(stream) as MyPic;
                if (obj != null)
                {
                    keys = obj.Keys;
                    KeyValue = obj.KeyValue;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
        /// <summary>
        /// 图片
        /// </summary>
        private string keys
        {
            get
            {
                return textBox1.Text.Trim();
            }
            set
            {
                textBox1.Text = value;
            }
        }
        private string KeyValue
        {
            get
            {
                return textBox2.Text.Trim();
            }
            set
            {
                textBox2.Text = value;
            }
        }
        private void InitMemoryMappedFile()
        {
            try
            {
                memoryFile = MemoryMappedFile.CreateOrOpen("111111", FileSize);
                stream = memoryFile.CreateViewStream();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                Close();
            }
        }
    }
} --------------------编程问答--------------------   异常图片
补充:.NET技术 ,  C#
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,