} // end of function - StartReader /*======================= PROTECTED =====================================*/ /************************ Events *****************************************/ /************************ Properties *************************************/ /************************ Construction ***********************************/ /************************ Methods ****************************************/ /// <summary> /// Explicit dispose method /// </summary> /// <param name="disposing"> /// Are we explicitly disposing, or called from the destructor /// </param> protected virtual void Dispose(bool disposing) { if (!CancelTokenSource.IsCancellationRequested) { CancelTokenSource.Cancel(); } // end of if - cancel has not already be requested try { #warning Should revisit this wait on the data reader DataReader.Wait(4000); } catch (Exception) { // Nothing to do with this exception at this point } if (disposing) { if (CloseStream && null != BaseStream) { BaseStream.Close(); BaseStream.Dispose(); } // end of if - we should close the base stream CancelTokenSource.Dispose(); } // end of if - explicitly disposing BaseStream = null; CancelTokenSource = null; } // end of function - Dispose
private void StartInputProcessingThread() { try { CancelTokenSource?.Cancel(); CancelTokenSource?.Dispose(); } catch { } // After BlockInput is enabled, only simulated input coming from the same thread // will work. So we have to start a new thread that runs continuously and // processes a queue of input events. _inputProcessingThread = new Thread(() => { Logger.Write($"New input processing thread started on thread {Thread.CurrentThread.ManagedThreadId}."); CancelTokenSource = new CancellationTokenSource(); if (_inputBlocked) { ToggleBlockInput(true); } CheckQueue(CancelTokenSource.Token); }); _inputProcessingThread.SetApartmentState(ApartmentState.STA); _inputProcessingThread.Start(); }
private void DisposeCancelToken() { if (CancelTokenSource == null) { return; } CancelTokenSource.Dispose(); CancelTokenSource = null; }
private void DisposeCancelToken() { if (Interlocked.Decrement(ref _activeAsyncRequests) > 0) { return; } if (CancelTokenSource == null) { return; } CancelTokenSource.Dispose(); CancelTokenSource = null; }
protected virtual void Dispose(bool disposing) { if (!disposedValue) { if (disposing) { CancelTokenSource?.Cancel(); ComparerTask?.Wait(); CancelTokenSource?.Dispose(); ComparerTask?.Dispose(); LeftVideoFile?.Dispose(); RightVideoFile?.Dispose(); } disposedValue = true; } }
protected virtual void Dispose(bool safe) { if (safe) { if (videoRender != null) { videoRender.Dispose(); videoRender = null; } if (audioPlayer != null) { audioPlayer.Dispose(); audioPlayer = null; } if (videoDecoder != null) { videoDecoder.Dispose(); videoDecoder = null; } /*if (demuxPacketsTask != null) * { * demuxPacketsTask.Dispose(); * demuxPacketsTask = null; * }*/ if (CancelTokenSource != null) { CancelTokenSource.Dispose(); CancelTokenSource = null; } if (demuxPacketsCancellationTokenSource != null) { demuxPacketsCancellationTokenSource.Dispose(); demuxPacketsCancellationTokenSource = null; } if (videoRefreshTimer != null) { videoRefreshTimer.Dispose(); videoRefreshTimer = null; } if (audioRefreshTimer != null) { audioRefreshTimer.Dispose(); audioRefreshTimer = null; } } }
private void StartInputProcessingThread() { CancelTokenSource?.Cancel(); CancelTokenSource?.Dispose(); var newThread = new Thread(() => { Logger.Write($"New input processing thread started on thread {Thread.CurrentThread.ManagedThreadId}."); CancelTokenSource = new CancellationTokenSource(); if (inputBlocked) { ToggleBlockInput(true); } CheckQueue(CancelTokenSource.Token); }); newThread.SetApartmentState(ApartmentState.STA); newThread.Start(); }
private void Dispose(bool disposing) { if (CancelTokenSource != null) { CancelTokenSource.Cancel(); if (PrintQueueProcessorThread != null) { PrintQueueProcessorThread.Join(); } CancelTokenSource.Dispose(); } PrintQueueProcessorThread = null; CancelTokenSource = null; if (PrintServerDispatcherThread != null) { if (PrintServerDispatcher != null) { PrintServerDispatcher.InvokeShutdown(); } PrintServerDispatcherThread.Join(); } PrintServerDispatcher = null; PrintServerDispatcherThread = null; if (disposing) { Disposed = true; GC.SuppressFinalize(this); } }
private void Form1_Closing(object sender, FormClosingEventArgs e) { CancelTokenSource?.Dispose(); CancelTokenSource = null; speed.Close(); }
public virtual void Dispose() { CancelTokenSource?.Dispose(); Wait?.Dispose(); }
public virtual async void Execute() { try { TaskStartedAction?.Invoke(Data); } catch (Exception exception) { if (!HandleException(this, exception)) { throw; } } if (Handler == null) { throw new NullReferenceException($"Exception Handler must be non-null!"); } while (!CancelTokenSource.IsCancellationRequested) { try { if (Data.IsEmpty) { Wait.WaitOne(); Wait.Reset(); } if (CancelTokenSource.IsCancellationRequested) { break; } if (!Data.IsEmpty) { ProcessData(); } #if true if (RateLimitTimeSpan.TotalMilliseconds > 0) { await Task.Delay((int)RateLimitTimeSpan.TotalMilliseconds, CancelTokenSource.Token); } #else var start = DateTime.Now; if (RateLimitTimeSpan.TotalMilliseconds > 0) { await Task.Delay((int)RateLimitTimeSpan.TotalMilliseconds, CancelTokenSource.Token); var duration = DateTime.Now - start; if (duration.TotalMilliseconds > 1000) { start = DateTime.MaxValue; } ; } else { RateLimitTimeSpan = TimeSpan.FromMilliseconds(2); } #endif } catch (ObjectDisposedException) { // Don't handle this exception, only causes more errors } catch (Exception exception) { if (!HandleException(this, exception)) { throw; } } } try { TaskEndingAction?.Invoke(Data); } catch (Exception exception) { if (!HandleException(this, exception)) { throw; } } CancelTokenSource.Dispose(); CancelTokenSource = null; Task = null; }