Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
141 views
in Technique[技术] by (71.8m points)

c# - Send/Receive message To/From two running application

I have two applications called SENDER and RECEIVER.

RECEIVER will be launched by SENDER with the System.Diagnostics.Process.Start method

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

Then we could use Win32.WM_COPYDATA in order send message to RECEIVER, but it needs MainWindowHandle so we can't.

What I need is ability to send and receive messages periodically by any method.

I checked the following link for a manual about MainWindowHandle, but it didn't help:

Send message to a Windows process (not its main window)

One solution might be an object from System.Diagnostics.Process which might help us to send messages to a process.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.

Different Machines

  • 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)

Always in same machine.

Preferred choice: 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 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.

Second preferred choice: Restful Web Service

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...