简体   繁体   中英

Send event to single process

I am currently using an EventWaitHandle to trigger a clean shutdown of a native process that doesnt have a window from a Windows Forms app. When I have multiple of these processes running at the same time, setting the event will stop all of them. Is there any way to send an event to a single selected process? I retain a Process variable for each of them.

EventWaitHandle Event = new EventWaitHandle(false, EventResetMode.ManualReset, "EventName");
Event.Set();

It sounds more like you want a named event handle per process.

You could use Process.Id to get a unique ID for each process, and use it to generate a unique string for each process.

Because the process ID is global, it makes it safe to assume that the ID can be used by both processes correctly.

You can then append this number onto some string like "MyProcessEvent" to give, say, "MyProcessEvent6345615". Then use that string to open the named EventWaitHandle in both processes.

Then your controller process can signal any of the processes it started using that name.

( A process finds its own ID via Process.GetCurrentProcess() ).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM