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);
}
}
#endregion