发送/接收信息到/从两个运行中的应用 [英] Send/Receive message To/From two running application

查看:128
本文介绍了发送/接收信息到/从两个运行中的应用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个应用程序调用的发送者和接收者。

I have two application called SENDER and RECEIVER.

接收器将推出由发送者的System.Diagnostics.Process 对象

RECEIVER will be launch by SENDER with System.Diagnostics.Process object

接收机将在隐藏模式下启动,因此不会有 MainWindowHandle

RECEIVER will be launched in hidden mode so it does not have MainWindowHandle.

然后,我们不能使用 Win32.WM_COPYDATA ,以便将消息发送到接收器,因为它需要 MainWindowHandle

Then we could not use Win32.WM_COPYDATA in order send message to RECEIVER , because it needs MainWindowHandle.

我需要的是通过任何方法定期发送和接收信息的能力。

我检查了以下链接手动 MainWindowHandle ,但它并没有帮助:

I was checked the following link for manual MainWindowHandle but it didn't help:

信息发送到一个Windows进程(而不是它的主要窗口)

一个解决方案可能是的System.Diagnostics.Process 其中一个有用的对象,帮助我们要发送消息给处理。

One solution might be a useful object of System.Diagnostics.Process which help us to send message to process.

推荐答案

有不同的方式来分享2个进程之间的信息。

There are different ways to share information between 2 processes.

首先,在你所想,如果两个进程都将是总是在同一台机器或者不能当你的应用程序扩展了。

First at all you have to think if both processes are going to be always in the same machine or not when your application scales up.

< STRONG>不同的机器


  • 使用TCP / UDP套接字连接(可能是最快的解决办法)

  • 使用MSMQ

  • 使用Web服务,WCF或RESTful Web服务。

  • 从在DB共同进入阅读。 (不推荐)

  • 命名管道(检查)(命名管道可在同一台机器上或飞通过网络)

  • Use TCP/UDP socket connection (Can be the quickest solution)
  • Use MSMQ
  • Use WebServices, WCF or Restful Web Service.
  • Reading from a common entry in a db. (Not recommended)
  • Named Pipes (Check this) (Named pipes can be in same machine or fly over a network)

始终在同一台机器上

  • Shared memory (You can use memory mapped files)
  • Reading from a common file (You can use FileWatcher)

首选:MSMQ

如果我是你,我会保留其在不同的机器流程的能力,所以我会使用,作为马腾建议的,使用的MSMQ两个窗口服务进行通信。为什么呢?

If I were you I would preserve the ability of having processes in different machines so I would use, as Maarten suggested, two windows services that uses MSMQ to communicate. Why?


  1. MSMQ允许你不要失去消息(如果接收器被关闭)

  2. MSMQ让你在同一台机器上还是在不同的机器进程

  3. Windows服务,让您启动/停止进程很容易

  4. Windows服务可以的能力我监视我的SNMP和一般来说,他们使用Windows管理工具,轻松地集成

  1. MSMQ allows you not to lose messages (in case RECEIVER is down)
  2. MSMQ allows you to have processes in same machine or in different machines
  3. Windows service give you the ability to start/stop the processes easily
  4. Windows service can me monitored my SNMP and in general they integrate easily with windows admin tools.

第二个最佳选择。RESTful Web服务

如果你不想使用MSMQ我会使用IIS举办了两场RESTful Web服务进行通信这两个进程。如果你有一个场景,其中接收器不感兴趣的,如果他们迟到SENDER信息很可能是有用的。

If you don't want to use MSMQ I would use two Restful Web Service hosted in IIS to communicate both processes. It can be useful if you have an scenario where RECEIVER is not interested in messages from SENDER if they arrive late.

这篇关于发送/接收信息到/从两个运行中的应用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆