There are times when we encounter the need to interoperate between two processes in some way, for example, you can try to have two processes continuously monitor an external file, which records the data of the respective processes, as well as the ability to use network ports for interprocess communication, to share memory area records, and to pass data on their processes. Here's how to implement communication between two processes using message delivery and processing under. Net.
Yes, the message here refers to the Windows message mechanism, for I rookie, you can easily understand the Windows message mechanism: Windows system can run a lot of applications at the same time, Windows system to let a program do one thing, It will send a message to the program to tell the program what to do.
First introduce the Windows API method SendMessage:
1 [DllImport ("User32.dll""SendMessage")] 2privatestaticexternint int msg, INTPTR WP, IntPtr LP);
Overrides the message processing process for the form object specified for the response message
1 protected Override voidWndProc (refSystem.Windows.Forms.Message msg)2 {3 Switch(Msg. MSG)4 {5 Case 0x0400:6 BOOLONOFF = Convert.toboolean ((int) Msg. LParam);7 Break;8 default:9 Base. WndProc (refmsg); Ten Break; One } A}
Well, the code above implements a custom message that receives the message address (ID) of the 0x0400 program.
Now all you need to do is write the contents of the message in the project you are sending the message to
1 0x0400, (INTPTR)0, (IntPtr)1);
. NET enables process interoperability with messages for interprocess communication