private void TheStartup(object o) { _commanderService.Start(); var bus = BusDriver.Instance.GetBus(CommanderService.CommandManagerBusName); bus.SubscribeHandler<TestedConfigurationMessage>((message) => { if (message.Exceptions.Any()) { throw message.Exceptions.First(); } IsRunning = true; _folderWatcherService.Start(); _startOrStopSignalled = false; var commanderStartedEventArgs = new CommanderStartedEventArgs(); RaiseAsynchronousOnCommanderStartedEvent(commanderStartedEventArgs); }); var testConfigurationMessage = new TestConfigurationMessage() { CorrelationId = CombGuid.Generate() }; bus.Publish(testConfigurationMessage); }
/// <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 RaiseOnCommanderStartedEvent(CommanderStartedEventArgs 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. CommanderStartedEventHandler eventHandler; if (!Monitor.TryEnter(_commanderStartedEventLock, _lockTimeout)) { throw new ApplicationException("Timeout waiting for lock - RaiseOnCommanderStartedEvent"); } try { eventHandler = _commanderStartedEvent; } finally { Monitor.Exit(_commanderStartedEventLock); } OnCommanderStartedEvent(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 RaiseAsynchronousOnCommanderStartedEvent(CommanderStartedEventArgs e) { _asyncOperation.Post(new SendOrPostCallback(AsynchronousOnCommanderStartedEventRaised), 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 RaiseCrossThreadOnCommanderStartedEvent(CommanderStartedEventArgs e) { _asyncOperation.SynchronizationContext.Send(new SendOrPostCallback(AsynchronousOnCommanderStartedEventRaised), e); }
/// <summary> /// Template method to add default behaviour for the event /// </summary> private void OnCommanderStartedEvent(CommanderStartedEventArgs e) { // TODO: Implement default behaviour of OnCommanderStartedEvent }
private void OnCommanderStarted(object sender, CommanderStartedEventArgs e) { SetRunningState(true); _logger.Info("Talifun Commander service started"); }