简体   繁体   中英

How can I tie together the lifetime of two processes in C#?

I have an application that instantiates two distinct processes in C#. Let them be A and B.

Usually, launching A would launch B under the hood. Because of a product bug on a specific version, for that faulty version I need to use a workaround based on launching process B first and then process A on top of it.

Everything works fine functionality-wise, but closing A won't close B this way. Because B ends up having no window when A comes into play, it cannot be nicely closed after closing A (if it could, I wouldn't have this problem) and must be killed with task manager.

Is there any way I can tie together the two C# Process objects, so that closing A would trigger the closing of B?

Note: Killing them inside the app I'm writing is not an option, because user must decide when the A & B ensemble gets closed

You can use inter-process communication techniques and classes like named system mutexes, EventWaitHandle , sockets, etc. A very similar question and solution can be found on another stackoverflow page

public EventWaitHandle (bool initialState, System.Threading.EventResetMode mode, string? name, out bool? createdNew);

name String The name, if the synchronization object is to be shared with other processes; otherwise, null or an empty string. The name is case-sensitive.

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