private void Resuming(object sender, HostResumingEventArgs args) { // // The host is telling us we're being resumed. At this point, code will // already be running in the process, so a past timer may still expire and // cause the code in Tick to run. Two interleavings are possible now: // // 1) We enter the gate first, and will adjust the cumulative inactive // time delta used for correction. The code in Tick will have the // illusion nothing happened and find itself RUNNING when entering // the gate, resuming activities as before. // // 2) The code in Tick enters the gate first, and takes notice of the // currently SUSPENDED state. It leaves the gate, entering the wait // state for _resumeEvent. Next, we enter to adjust the cumulative // inactive time delta, switch to the RUNNING state and signal the // event for Tick to carry on and recompute its next due time based // on the new cumulative delta. // lock (_gate) { if (_runState == SUSPENDED) { _inactiveTime += _stopwatch.Elapsed - _suspendedAt; _runState = RUNNING; if (!Environment.HasShutdownStarted) { _resumeEvent.Set(); } } } }
private static void OnResuming(object sender, HostResumingEventArgs e) { var resuming = Resuming; if (resuming != null) resuming(sender, e); }