/// <summary> /// Dispose an exising SimpleDispatcher and stop running executables. /// </summary> public virtual void Stop() { lock (_runLock) { if (!IsRunning) { return; } _dispatcher.Dispose(); IsRunning = false; lock (_updateLock) { while (_liveExecutables.Any()) { var executable = _liveExecutables.First().Value; RemoveExecutableFromRunningList(executable); if (executable is IActivityMachine) { (executable as IActivityMachine).EmergencyQuit(); } } while (_delayedMachines.Any()) { var machine = _delayedMachines.First(); RemoveMachineFromDelayedList(machine); machine.Quit(); } } } }
private void Dispose() { lock (_disposeLock) { if (_disposed) { return; } _disposed = true; } if (_dispatcher != null) { _dispatcher.Dispose(); } _dispatcher = null; try { _waitForFinishEvent.Dispose(); } catch (ObjectDisposedException) { //nothing to do. wait handle was disposed } LogService.Log(LogType.System, LogMessageType.Debug, GetType().Name, string.Format(CultureInfo.InvariantCulture, "{0} is disposed.", Name)); }
protected void Teardown() { // Only dispose the dispatcher if it was created here. if (_hasLocalDispatcher) { // We are here because the FinalNode's ExitBehavior is running on the Dispatcher. // Attempting to dispose of the Dispatcher from the final executable using the Dispatcher's // own thread will cause the Dispatcher to kill (abort) it's thread. // That thread abort can be avoided by giving the Dispatcher cleanup to a different thread, // which allows the currently executing ExitBehavior to finish cleanly first. Task.Factory.StartNew(() => { LogService.Log(LogType, LogMessageType.Debug, GetType().Name, "Waiting for local dispatcher '" + Name + "' to be empty."); _dispatcher.WaitUntilDone(); LogService.Log(LogType, LogMessageType.Debug, GetType().Name, "'" + Name + "' is disposing."); // We are now completely done with the dispatcher. _dispatcher.Dispose(); _dispatcher = null; }); } try { _finishedEvent.Dispose(); } catch (ObjectDisposedException) { // reset event was disposed } //Dispose the UML nodes DisposeNodes(InitialNode); if (FinalNode != null) { // THIS MAY BE A PROBLEM if SimpleDispatcher is made to dispose IExecutables after executing them. FinalNode.Dispose(); } Dispose(); }