. NET enables process interoperability with messages for interprocess communication

Source: Internet
Author: User

  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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.