public void Stop() { if (!IsRunning || _startOrStopSignalled) return; _startOrStopSignalled = true; _folderWatcherService.Stop(); _commanderService.Stop(); IsRunning = false; _startOrStopSignalled = false; var commanderStoppedEventArgs = new CommanderStoppedEventArgs(); RaiseAsynchronousOnCommanderStoppedEvent(commanderStoppedEventArgs); }
/// <summary> /// Will raise the event on the current thread synchronously. /// i.e. it will wait until all event handlers have processed the event. /// </summary> /// <param name="e">The state to be passed to the event.</param> private void RaiseOnCommanderStoppedEvent(CommanderStoppedEventArgs e) { // Make a temporary copy of the event to avoid possibility of // a race condition if the last subscriber unsubscribes // immediately after the null check and before the event is raised. CommanderStoppedEventHandler eventHandler; if (!Monitor.TryEnter(_commanderStoppedEventLock, _lockTimeout)) { throw new ApplicationException("Timeout waiting for lock - RaiseOnCommanderStoppedEvent"); } try { eventHandler = _commanderStoppedEvent; } finally { Monitor.Exit(_commanderStoppedEventLock); } OnCommanderStoppedEvent(e); if (eventHandler != null) { eventHandler(this, e); } }
/// <summary> /// Will raise the event on the calling thread asynchronously. /// i.e. it will immediatly continue processing even though event /// handlers have not processed the event yet. /// </summary> /// <param name="state">The state to be passed to the event.</param> private void RaiseAsynchronousOnCommanderStoppedEvent(CommanderStoppedEventArgs e) { _asyncOperation.Post(new SendOrPostCallback(AsynchronousOnCommanderStoppedEventRaised), e); }
/// <summary> /// Will raise the event on the calling thread synchronously. /// i.e. it will wait until all event handlers have processed the event. /// </summary> /// <param name="state">The state to be passed to the event.</param> private void RaiseCrossThreadOnCommanderStoppedEvent(CommanderStoppedEventArgs e) { _asyncOperation.SynchronizationContext.Send(new SendOrPostCallback(AsynchronousOnCommanderStoppedEventRaised), e); }
/// <summary> /// Template method to add default behaviour for the event /// </summary> private void OnCommanderStoppedEvent(CommanderStoppedEventArgs e) { // TODO: Implement default behaviour of OnCommanderStoppedEvent }
private void OnCommanderStopped(object sender, CommanderStoppedEventArgs e) { SetRunningState(false); _logger.Info("Talifun Commander service stopped"); }