关于WPF多窗口消息传递的简单实现

  

,在目前一些桌面端展示系统的应用中,需要多个子系统窗口进行信息交换,对于部署在同一台电脑上的各个子系统,可以通过集成windows系统的消息传递方式进行消息传递,但是假如将各个子系统部署在不同的电脑上,这种实现方式就有一定的局限性,要涉及到网络中的不同电脑进行通信、。net提供了可以建一个小的http服务器,可以绑定计算机的端口进行通信,且提供了异步的实现方式,能实现无阻塞的消息通信。

具体实现://启动一个监听,,并绑定端口,MSDN有详细参数说明   public  bool  StartListener (string[],前缀)   ,,,,,,,{   ,,,,,,,,,,,bool  isSuccess =,假;   ,,,,,,,,,,,if  (HttpListener.IsSupported)   ,,,,,,,,,,,{   ,,,,,,,,,,,,,,,HttpListener  listener =, new  HttpListener ();   ,,,,,,,,,,,,,,,foreach  (string  s 前缀拷贝)   ,,,,,,,,,,,,,,,{   ,,,,,,,,,,,,,,,,,,,listener.Prefixes.Add(年代);   ,,,,,,,,,,,,,,,}   ,,,,,,,,,,,,,,,listener.Start ();   ,,,,,,,,,,,,,,,var  result =, listener.BeginGetContext (new  AsyncCallback (ListenerCallback),侦听器);   ,,,,,,,,,,,,,,,isSuccess =,真的;   ,,,,,,,,,,,,,,,//Console.WriteLine (“Waiting  for  request 用be  processed  asyncronously。”);   ,,,,,,,,,,,,,,,//result.AsyncWaitHandle.WaitOne ();,,   ,,,,,,,,,,,,,,,//listener.Close (),,   ,,,,,,,,,,,}   ,,,,,,,,,,,return  isSuccess;   ,,,,,,,}      ,,,,,,,public  void  StopListener ()   ,,,,,,,{   ,,,,,,,,,,,if  (listener  !=, null)   ,,,,,,,,,,,{   ,,,,,,,,,,,,,,,if  (listener.IsListening)   ,,,,,,,,,,,,,,,{   ,,,,,,,,,,,,,,,,,,,listener.Stop ();   ,,,,,,,,,,,,,,,}   ,,,,,,,,,,,,,,,listener.Close ();   ,,,,,,,,,,,}   ,,,,,,,}//异步接收数据,并进行下一次的   ,,,,,,,private  void  ListenerCallback (IAsyncResult 结果)   ,,,,,,,{   ,,,,,,,,,,,HttpListener  listener =, (HttpListener) result.AsyncState;   ,,,,,,,,,,,HttpListenerContext  context =, listener.EndGetContext(结果);   ,,,,,,,,,,,HttpListenerRequest  request =, context.Request;   ,,,,,,,,,,,HttpListenerResponse  response =, context.Response;   ,,,,,,,,,,,response.ContentType =,“text/plain”;   ,,,,,,,,,,,System.IO.Stream  output =, response.OutputStream;   ,,,,,,,,,,,string  responseString =,“真正的”;   ,,,,,,,,,,,试一试   ,,,,,,,,,,,{   ,,,,,,,,,,,,,,,if  (MessageAction  !=, null)   ,,,,,,,,,,,,,,,{   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null

关于WPF多窗口消息传递的简单实现