I have two .net 2 winforms, each has its own project. project 1 is main form and project 2 is a child form. and now I would like to know how to make the child form close it self if main form is no longer active.
killing child form on exit doesnt work, because main form can be killed by task manager.
If I understand correctly, what you call a ‘child form’ is actually another WinForms app running in a separate process?
In addition, I take it (from your “because main form can be killed by task manager” comment) that you want the exiting behaviour to be resilient to cases when the main-app is forcefully killed.
One way would be to get the ‘child app’ to listen to the
Process.Exitedevent of the ‘main app’, and exit if it fires.I imagine it would look something like: