Send/Receive message To/From two running application
Send/Receive message To/From two running application
I have two application called SENDER and RECEIVER.
RECEIVER will be launch by SENDER with System.Diagnostics.Process
object
System.Diagnostics.Process
RECEIVER will be launched in hidden mode so it does not have MainWindowHandle
.
MainWindowHandle
Then we could not use Win32.WM_COPYDATA
in order send message to RECEIVER , because it needs MainWindowHandle
.
Win32.WM_COPYDATA
MainWindowHandle
What I need is ability to send and receive message periodically by any method.
I was checked the following link for manual MainWindowHandle
but it didn't help:
MainWindowHandle
Send message to a Windows process (not its main window)
One solution might be a useful object of System.Diagnostics.Process
which help us to send message to process.
System.Diagnostics.Process
Sorry, I was assuming that you were having processes in a server. Could you give more info about scenario? Where will be SENDER and RECEIVER installed, size of message, which constrains do you have...
– Oscar Foley
Jul 6 '12 at 9:42
Message is a simple string (maybe in JSON format). I want send a simple string to RECEIVER then RECEIVER collect information from internet then RECEIVER send back populated information to SENDER as a simple string.
– Hamid
Jul 6 '12 at 9:59
3 Answers
3
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
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?
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.
Named pipes can also be used over the network. Also do note that WCF can be self-hosted by a process, there is no need for IIS. WCF also allows synchronous communication.
– ken2k
Jul 6 '12 at 9:25
+1 to your comment. You are right. Never used named pipes in C#. WCF can be self-hosted or IIS hosted... I am used to host it in IIS. WCF allows synchronous communication by default and asynchronous if you code it this way. Not sure what Hamid needs. I asked him for more info. Thanks :)
– Oscar Foley
Jul 6 '12 at 9:47
I worked with WCF before, but you say that WCF might be works slow, right? Speed is the main subject in my application.
– Hamid
Jul 6 '12 at 10:02
If speed is a requirement then I would go for a TCP or UDP socket connection (TCP probably if you need reliability and UDP only in the case message lose importance with time. For example if you are sending the last datetime your client was a live, UDP makes sense because if message didn't arrived you don't want TCP to resend an old deprecated message... you prefer have another UDP message sent)
– Oscar Foley
Jul 6 '12 at 10:08
Where is SendMessage API in the list?
– Martin.Martinsson
Jul 27 at 18:52
I think MSMQ is a good option.
Old question, I know.
Stumbled on it, as I have a somewhat similar task.
One app started from the another - it will end again, but nobody knows when.
1. app can start 2. again, but must not until previous instances of 2. has exited.
Always on same PC (and Windoze).
The simple thing is off hand to use the registry to set a value, when 2. program is running, and remove/reset it again when it exits.
1. app can check the registry to see if it is OK to start another instance of the 2. app.
You can also use the registry to pass values between the apps.
Drawback is, that apps must poll the registry, instead of sending messages. Simpler but less effective.
So probably dependent on what it is needed for.
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
Please suggest a solution which would not required an installation. like as MSMQ which might be not installed on end user windows.
– Hamid
Jul 6 '12 at 9:36