1

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

  • Are you fixing this in compiled code or are you tweaking a "batch" file launcher process to get B to start first. – Sql Surfer Mar 22 '21 at 23:19
  • @SqlSurfer compiled code. `Process` objects that instantiate `.exe`s – Robi Szarvas Mar 23 '21 at 06:42
  • If B should always close if A is closing than add code to B that self shuts down if it does not see A running for more than 10 seconds. If you have to tie the instances together than use a command line param or the process ID to know which one is "owned" by the one that started the other process. In effect make both A and B smart. The top "window" handle or process id can be used as an ID to tie them together. I would look into a process C that manages all this. (Detail - .NET "classic" and .NET core behave a little differently when launching processes.) – Sql Surfer Mar 23 '21 at 12:16

1 Answers1

0

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.

Igor
  • 266
  • 1
  • 3
  • 13