Hi all,
I am using C#.Net Visual Team Studio 2008.
I have two (or more), applications on the same PC and need to transfer simple text messages between the app's.
Since i just want to transfer text messages, i expect to use a clean and simple code to do it.
I don't want to use databases, files and other things like this, i want to use something inside the framework 3.5.
I figured out on how to do this using message queue from windows, that was very simple, but all my users need to install Windows Message Queue because it is not installed by default, even in Windows 7.
I tried to use Named Pipes, but damm, that is too complex. The samples that i found uses WaitForConnection() method, but this is not cool because my application freezes at this line waiting forever for a connection...
So, i figured out that i can use BeginWaitForConnection instead of WaitForConnection but i did not found any examples about it. Another thing about named pipes is that on app will be a server and another a client, this is not what i want, i need app1 and app2 talking each other, full duplex :)
So i ask you guys:
is the named pipe the best method to use for me?
if it was, does anybody has a sample code using BeginWaitForConnection to help me?
Example:
I have APP1, and APP2
APP1 launches APP2 and show to the user a screen: waiting...(on APP1), and a Cancel button
So, user can cancel if he wants...
APP2 will appear and the user will interface with it, at some point APP2 need to tell to APP1 that the procedure was executed succefully or not and quit.
APP1 is waiting the response from APP2 and user cannot do anything until the messages come or the CANCEL button is pressed. So, APP1 can wait inside a while...doevents
thanks!!
Loading
Sam HobbsPosted Apr 9, 2010, 9:02 PM
In the old days before managed code, Windows programmers used the WM_COPYDATA message. It still works but to use it you have to use the unmanaged Windows API. The attached project is a sample, but note that for the purposes of a sample, the program does both sending and receiving. Both sending and receiving WM_COPYDATA messages in the same program would be foolish to do in a real program. If you use my sample, you promise to read the documentation of the WM_COPYDATA message; there are a couple of requirements in the Windows API documentation that you need to understand. Well, I will give you a clue. One thing is that you must use SendMessage (never PostMessage) to send a WM_COPYDATA message. Anothing thing is that your WM_COPYDATA message handler must copy the data before returning.
For you, you need to determine how your programs will obtain the handle of the other window. You must have a handle for the SendMessage to send to.
Sam HobbsPosted Apr 12, 2010, 2:18 PM
EduardoPosted Apr 12, 2010, 7:24 AM
I don't want to use SEND_MESSAGE because of the DLL that i need to import and remoting is to much code for a simple thing.
Anyways, thanks!