日期:2014-05-19  浏览次数:21048 次

关于进程间通信的问题
关于进程间通信的问题,给点程序参考一下

------解决方案--------------------
我的Blog上有一篇讲用Windows消息实现进程间通讯的文章,你可以去看看!
http://wzd24.cnblogs.com
------解决方案--------------------
Use WM_COPYDATA to send data to/from C++ and C# Windows processes
http://www.codeproject.com/csharp/wm_copydata_use.asp
------解决方案--------------------
using System;
using System.Collections.Generic;
using System.Text;
using System.Net;
using System.Net.Sockets;
using System.Diagnostics;

namespace UDPComm
{
public class UDP
{
public delegate void dlg_UDPMsgHandler(string receivebytes);
public static event dlg_UDPMsgHandler UDPMsgArrived;

dlg_UDPMsgHandler udpmsghandle = new dlg_UDPMsgHandler(UDPRaiseEvent);

public static void Send(string range, string datagram)
{
UdpClient sender = new UdpClient();
IPEndPoint endPoint = new IPEndPoint(IPAddress.Parse(range),10001);

try
{
datagram += (char)3;
byte[] bytes = Encoding.ASCII.GetBytes(datagram);
sender.Send(bytes,bytes.Length,endPoint);
}
catch (Exception ex)
{
Debug.WriteLine(ex.ToString());
return;
}
finally
{
sender.Close();
}
}

public static void Receiver()
{

UdpClient receiveUdpClient = new UdpClient(10001);
IPEndPoint RemoteIPEndPoint = null;

try
{
while (true)
{
byte[] receiveBytes = receiveUdpClient.Receive(ref RemoteIPEndPoint);
string returnData = Encoding.ASCII.GetString(receiveBytes);
if (returnData.IndexOf((char)3) > -1)
{
UDPRaiseEvent(returnData.Substring(0, returnData.Length - 1));
}
else
return;
}
}
catch (Exception ex)
{
Debug.WriteLine(ex.ToString());
return;
}
}

public static void UDPRaiseEvent(string recebytes)
{
UDPMsgArrived(recebytes);
}
}
}
把这个作为DLL加到A和B中
------解决方案--------------------
在C#的应用程序里边可以通过多种方式:
方式一、Windows消息
关于这方面的详细资料在cnblogs中有详细介绍
http://www.cnblogs.com/PeanutLee/archive/2006/11/03/548538.html

方式二、文件方式
将内存数据保存为文件的形式,可以使用.NET的序列化功能进行读入和读出

方式三、socket通信方式
.NET的Socket通信也很方便。

这里推荐第一种方式。


------解决方案--------------------
C#中也有Socket

------解决方案--------------------
也有Socket,也可以使用Message