private void ToExited(ProcessExitState exitState, long timestamp, int exitCode, string errorText) { lock (this) { if (state == State.Exited) { // duplicate exit; ignore it return; } // this can be reached from any preceding state state = State.Exited; } watcher.OnExited(exitState, timestamp, exitCode, errorText); }