/// <summary> /// Starts the execution of <see cref="ServiceProcess"/>. /// </summary> /// <param name="arguments">Arguments to be passed in to the <see cref="ExecutionMethod"/>.</param> public void Start(object[] arguments) { // Start the execution on a separate thread. #if ThreadTracking m_processThread = new ManagedThread(InvokeExecutionMethod); m_processThread.Name = "GSF.ServiceProcess.ServiceProcess.InvokeExecutionMethod() [" + m_name + "]"; #else m_processThread = new Thread(InvokeExecutionMethod); #endif m_processThread.Start(arguments); }
/// <summary> /// Connects the <see cref="FileClient"/> to the <see cref="FileStream"/> asynchronously. /// </summary> /// <exception cref="InvalidOperationException">Attempt is made to connect the <see cref="FileClient"/> when it is not disconnected.</exception> /// <returns><see cref="WaitHandle"/> for the asynchronous operation.</returns> public override WaitHandle ConnectAsync() { m_connectionHandle = (ManualResetEvent)base.ConnectAsync(); m_fileClient.SetReceiveBuffer(ReceiveBufferSize); #if ThreadTracking m_connectionThread = new ManagedThread(OpenFile); m_connectionThread.Name = "GSF.Communication.FileClient.OpenFile()"; #else m_connectionThread = new Thread(OpenFile); #endif m_connectionThread.Start(); return(m_connectionHandle); }
/// <summary> /// Starts the <see cref="ScheduleManager"/> asynchronously if not running. /// </summary> public void Start() { if (!IsRunning && (object)m_startTimerThread == null) { // Initialize if uninitialized. Initialize(); // Initialize timer that checks schedules. m_timer = new Timer(TimerInterval); m_timer.Elapsed += m_timer_Elapsed; // Spawn new thread to start timer at top of the minute. #if ThreadTracking m_startTimerThread = new ManagedThread(StartTimer); m_startTimerThread.Name = "GSF.Scheduling.ScheduleManager.StartTimer()"; #else m_startTimerThread = new Thread(StartTimer); m_startTimerThread.IsBackground = true; #endif m_startTimerThread.Start(); } }
public virtual void Run() { CancellationToken = new CancellationToken(); ReadChunksQueue = new ConcurrentQueue <IChunk>(CancellationToken, Options.MaxBuffers, Options.VerboseOutput); ExecutedChunksQueue = new IndexedConcurrentQueue <IChunk>(CancellationToken, Options.MaxBuffers, Options.VerboseOutput); var execThread = new ManagedThread(Execute, OnException); execThread.Start(); var writeThread = new ManagedThread(Write, OnException); writeThread.Start(); try { using (var inputStream = new FileStream(Options.Input, FileMode.Open, FileAccess.Read, FileShare.Read)) { using (var bufferedStream = new BufferedStream(inputStream, Options.ReadBufferSize)) { ReadStream(inputStream); } } } catch (Exception e) { OnException(e); } execThread.Join(); writeThread.Join(); if (ErrorOccured) { throw _exception; } ReadChunksQueue = null; ExecutedChunksQueue = null; }
/// <summary> /// Connects the <see cref="SerialClient"/> to the <see cref="SerialPort"/> asynchronously. /// </summary> /// <exception cref="InvalidOperationException">Attempt is made to connect the <see cref="SerialClient"/> when it is connected.</exception> /// <returns><see cref="WaitHandle"/> for the asynchronous operation.</returns> public override WaitHandle ConnectAsync() { m_connectionHandle = (ManualResetEvent)base.ConnectAsync(); m_serialClient.SetReceiveBuffer(ReceiveBufferSize); m_serialClient.Provider = new SerialPort(); #if !MONO m_serialClient.Provider.ReceivedBytesThreshold = m_receivedBytesThreshold; #endif m_serialClient.Provider.DataReceived += SerialPort_DataReceived; m_serialClient.Provider.ErrorReceived += SerialPort_ErrorReceived; m_serialClient.Provider.PortName = m_connectData["port"]; m_serialClient.Provider.BaudRate = int.Parse(m_connectData["baudrate"]); m_serialClient.Provider.DataBits = int.Parse(m_connectData["databits"]); m_serialClient.Provider.Parity = (Parity)(Enum.Parse(typeof(Parity), m_connectData["parity"], true)); m_serialClient.Provider.StopBits = (StopBits)(Enum.Parse(typeof(StopBits), m_connectData["stopbits"], true)); if (m_connectData.ContainsKey("dtrenable")) { m_serialClient.Provider.DtrEnable = m_connectData["dtrenable"].ParseBoolean(); } if (m_connectData.ContainsKey("rtsenable")) { m_serialClient.Provider.RtsEnable = m_connectData["rtsenable"].ParseBoolean(); } #if ThreadTracking m_connectionThread = new ManagedThread(OpenPort); m_connectionThread.Name = "GSF.Communication.SerialClient.OpenPort()"; #else m_connectionThread = new Thread(OpenPort); #endif m_connectionThread.Start(); return(m_connectionHandle); }