Created
August 31, 2020 02:45
-
-
Save joncloud/679dab6747bd06c754b016af45c69c7f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Diagnostics; | |
using System.Threading; | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
var processes = Process.GetProcessesByName("Notepad3"); | |
var countdown = new CountdownEvent(processes.Length); | |
foreach (var p in processes) | |
{ | |
p.EnableRaisingEvents = true; | |
p.Exited += delegate | |
{ | |
countdown.Signal(); | |
}; | |
} | |
Console.WriteLine($"Waiting for {processes.Length} processes to exit"); | |
countdown.Wait(); | |
Console.WriteLine("Exiting"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment