/// <summary> /// /// </summary> protected virtual void Uninitialize( ) { try { AppDomain.Unload(this.AppDomain); this.AppDomain = null; this.RealFlow = null; this.Initialized = false; } catch (StackOverflowException) { throw; } catch (OutOfMemoryException) { throw; } catch (Exception x) { string msg = "Could not unload an appdomain."; if (this.AppDomain != null) { msg = string.Format("Could not unload appdomain {0}", this.AppDomain.FriendlyName); } CompuFlowException rfe = new CompuFlowException(msg, x); throw rfe; } }
/// <summary> /// Worker method. /// </summary> private void WorkerMethod( ) { while (!this.MarkedForTermination) { try { this.WaitHandle.WaitOne( ); // // Terminate flow marked and remove references to them. // lock (this) { List <TTransparentFlow> removeList = new List <TTransparentFlow>( ); foreach (TTransparentFlow transparentFlow in this.Flows) { if (transparentFlow.MarkedForTermination && !transparentFlow.Terminated) { try { transparentFlow.Terminate( ); // // Add the flow to list of flows to be removed. // removeList.Add(transparentFlow); } catch (StackOverflowException) { throw; } catch (OutOfMemoryException) { throw; } catch (ThreadAbortException) { throw; } catch (Exception e) { ExceptionManager.PublishException(e, "Error"); } } } // // Remove the flows. // foreach (TTransparentFlow transparentFlow in removeList) { this.Flows.Remove(transparentFlow); } }// lock // // Execute flow. // while (this.Queue.Count > 0) { FlowManifest flowManifest = this.Queue.Dequeue( ); bool bExecuted = false; foreach (TTransparentFlow transparentFlow in this.Flows) { if (transparentFlow.Flow.FlowID == flowManifest.FlowID && !transparentFlow.MarkedForTermination) { try { this.CurrentFlowManifest = flowManifest; transparentFlow.Execute(flowManifest); } catch (StackOverflowException) { throw; } catch (OutOfMemoryException) { throw; } catch (ThreadAbortException) { throw; } catch (Exception e) { string msg = string.Format("TransparentFlow threw an exception while executing flow with FlowID='{0}'.", flowManifest.FlowID); ExceptionManager.PublishException(e, "Error"); } finally { bExecuted = true; } } // if } // foreach if (!bExecuted) { string msg = string.Format("No TransparentFlow to handle FlowID = '{0}'.", flowManifest.FlowID); ExceptionManager.PublishException(new CompuFlowException(msg), "Warning"); } } } catch (StackOverflowException) { throw; } catch (OutOfMemoryException) { throw; } catch (ThreadAbortException tae) { CompuFlowException rfe = new CompuFlowException("Could not continue execution.", tae); ExceptionManager.PublishException(rfe, "Error"); this.Terminate( ); //System.ServiceProcess.ServiceController sc = new System.ServiceProcess.ServiceController( "Psr3Engine" ); //sc.Stop( ); } catch (Exception x) { ExceptionManager.PublishException(x, "Error"); } }// while // // Terminate all flows. // foreach (TTransparentFlow transparentFlow in this.Flows) { transparentFlow.Terminate( ); } lock (this) { this.Flows.Clear( ); } this.Terminated = true; }