Created
December 13, 2019 10:53
-
-
Save gsscoder/255befc5221890e679e89e781befb190 to your computer and use it in GitHub Desktop.
Demonstrates how to detect end of a running process
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
// purpose: detect process end | |
// demo: | |
// - launch firefox | |
// - launch this program | |
// - close firefox and see 'died' | |
// notes: | |
// - may need sudo on *nix systems | |
using System; | |
using System.Diagnostics; | |
using System.Linq; | |
class Program | |
{ | |
static Process _process; | |
static void Main(string[] args) | |
{ | |
var allProcesses = Process.GetProcesses(); | |
_process = allProcesses.Where(x => x.ProcessName.Contains("firefox")).First(); | |
_process.EnableRaisingEvents = true; | |
_process.Exited += new EventHandler(OnExit); | |
Console.WriteLine("Hit a key to exit"); | |
Console.ReadLine(); | |
} | |
static void OnExit(object sender, System.EventArgs e) | |
{ | |
Console.WriteLine("died"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment