Skip to content

Instantly share code, notes, and snippets.

@joncloud
Created August 31, 2020 02:45
Show Gist options
  • Save joncloud/679dab6747bd06c754b016af45c69c7f to your computer and use it in GitHub Desktop.
Save joncloud/679dab6747bd06c754b016af45c69c7f to your computer and use it in GitHub Desktop.
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