Closing multiple projects in Visual Studio

I have two projects running in Visual Studio but whenever I exit one the other keeps running. How can I close both?

Ps: I’m using Application.Exit() to close the first one

>Solution :

If you want to use Application.Exit() to close the first process, and you want to close the second process at the same time, try adding the following lines immediately before you call Application.Exit():

Process[] processes = Process.GetProcessesByName("SecondProcess");

where SecondProcess is the process name of your second process. (You will also need to add a using reference to System.Diagnostics.)

This code assumes exactly one such process will be running; if that’s not necessarily the case, you might need to do more.

Use with caution: killing a running process like this might not be advisable! Other methods are possible and probably better but without more information about your exact setup it’s hard to know which approach to suggest.

Leave a Reply