Bug 26362

Summary: [Process] Exited event raised while process still running
Product: [Mono] Class Libraries Reporter: Sandy Armstrong [MSFT] <sandy>
Component: mscorlibAssignee: marcos.henrich
Status: RESOLVED FIXED    
Severity: normal CC: marcos.henrich, mono-bugs+mono
Priority: ---    
Version: 3.12.0   
Target Milestone: Untriaged   
Hardware: PC   
OS: Mac OS   
Tags: Is this bug a regression?: ---
Last known good build:

Description Sandy Armstrong [MSFT] 2015-01-23 17:03:10 UTC
1. Get a process from GetProcessById or GetProcesses
2. Set EnableRaisingEvents to true
3. Add a handler for the Exited event

Expected results:

Exited event handler is called when the associated process exits.

Actual results:

Exited event handler is triggered almost immediately.


Example:

	var cp = Process.GetCurrentProcess ();

	foreach (var p in Process.GetProcesses ()) {
		try {
			if (p.Id != cp.Id && !p.HasExited) {
				Console.WriteLine ("Name: {0} StartTime: {1}", p.ProcessName, p.StartTime);
				if (p.ProcessName.StartsWith ("ssh-agent")) {
					p.EnableRaisingEvents = true;
					p.Exited += (s, e) => {
						Console.WriteLine ("ssh-agent exited");
					};
				}
			}
		} catch {
		}
	}


Output (even though ssh-agent is still very much alive):

    Name: ssh-agent StartTime: 12/31/1600 4:00:00 PM
    Name: lldb StartTime: 12/31/1600 4:00:00 PM
    ssh-agent exited
Comment 1 Sandy Armstrong [MSFT] 2015-01-23 17:12:06 UTC
Works on MS.NET, not Mono 3.12.0 on OS X Yosemite.
Comment 2 marcos.henrich 2015-04-08 09:48:47 UTC
Hi Sandy,

Thanks for the bug report.

The fix to this issue can be found in the following pull request:
https://github.com/mono/mono/pull/1691
Comment 3 marcos.henrich 2015-04-27 14:14:38 UTC
Fixed in master e097a98f3bd9082c7d03fa580b604c0228b4ad67.
https://github.com/mono/mono/commit/e097a98f3bd9082c7d03fa580b604c0228b4ad67