/// <summary> /// Create a new LogDownloader /// </summary> /// <param name="isAsyncTransfer">Determines if this machine will be set up asyncronus transfers.</param> /// <param name="threadName">The name to report in closing operations for this binary socket.</param> /// <param name="closingWorker">The closing worker to add this binary socket too.</param> protected ThreadedTransferMachine(bool isAsyncTransfer, string threadName, ClosingWorker closingWorker) : base(threadName) { // add thread to the closing worker closingWorker?.AddThread(this); // initialize the StateMachine WorkerState = new StateDefinition(); if (isAsyncTransfer) { MachineFunctions.InitializeStates(WorkerStateMachine = new StepDefinition(threadName, true, WorkerState) { #region StateMachine SubSteps = new List <StepDefinition> { new StepDefinition("Transfer Packet") { Delegate = StateMachine_TransferPacket, DelayTimeMs = 500 }, new StepDefinition("Packet Timeout") { Delegate = StateMachine_PacketTimeout, DelayTimeMs = 0 }, new StepDefinition("Complete") { Delegate = StateMachine_Complete, DelayTimeMs = 200 } } #endregion // StateMachine }); } else { MachineFunctions.InitializeStates(WorkerStateMachine = new StepDefinition(threadName, true, WorkerState) { #region StateMachine SubSteps = new List <StepDefinition> { new StepDefinition("Transfer Packet") { Delegate = StateMachine_TransferPacket, DelayTimeMs = 0 }, new StepDefinition("Complete") { Delegate = StateMachine_Complete, DelayTimeMs = 200 } } #endregion // StateMachine }); } // start the StateMachine in the Complete state MachineFunctions.JumpToLast(WorkerStateMachine); // initialize ThreadingBase WorkerThreads = new List <ThreadInfo> { new ThreadInfo(new Thread(Worker), "State Machine", threadName, WorkerStateMachine) }; }
/// <summary> /// Creates a new ThreadedComPortBase object. /// </summary> /// <param name="threadName">The threadname to report during closing and error events.</param> /// <param name="closingWorker">The closing worker this thread should subscribe too.</param> /// <param name="connectionParameters">The ComParameters to use when testing connections</param> /// <param name="mode">Which connection mode to use when selecting ComPorts to test.</param> /// <param name="selectionRule">The selectionRule to use when mode = SelectionRule.</param> public ThreadedComPortBase(string threadName, ClosingWorker closingWorker, ComParameters connectionParameters, ConnectionMode mode, Func <ComPortInfo, bool> selectionRule = null) : base(threadName) { _threadName = threadName; closingWorker?.AddThread(this); ConnectionParameters.CopyFrom(connectionParameters); // initialize the StateMachine WorkerState = new StateDefinition(); MachineFunctions.InitializeStates(WorkerStateMachine = new StepDefinition(threadName, true, WorkerState) { #region StateMachine SubSteps = new List <StepDefinition> { new StepDefinition("Searching") { Delegate = StateMachine_Searching, DelayTimeMs = 200 }, new StepDefinition("Connection Check") { Delegate = StateMachine_ConnectionCheck, DelayTimeMs = 200 }, new StepDefinition("Complete") { Delegate = StateMachine_Complete, DelayTimeMs = 200 } } #endregion // StateMachine }); // set the mode for this com port ChangeMode(mode, selectionRule); // initialize ThreadingBase WorkerThreads = new List <ThreadInfo> { new ThreadInfo(new Thread(Worker), "State Machine", threadName, WorkerStateMachine) }; }