/// <summary> /// Start the grab process in a separate thread. Once started, use the ImageGrabbed event handler and RetrieveGrayFrame/RetrieveBgrFrame to obtain the images. /// </summary> #if WITH_SERVICE_MODEL /// <param name="eh">An exception handler. If provided, it will be used to handle exception in the capture thread.</param> #endif public void Start( #if WITH_SERVICE_MODEL System.ServiceModel.Dispatcher.ExceptionHandler eh = null #endif ) { if (_grabState == GrabState.Pause) { _grabState = GrabState.Running; _pauseEvent.Set(); } else if (_grabState == GrabState.Stopped || _grabState == GrabState.Stopping) { _grabState = GrabState.Running; #if NETSTANDARD1_4 Task t = new Task(Run); t.Start(); #elif NETFX_CORE ThreadPool.RunAsync(delegate { Run(); }); #elif !WITH_SERVICE_MODEL ThreadPool.QueueUserWorkItem(delegate { Run(); }); #else ThreadPool.QueueUserWorkItem(delegate { Run(eh); }); #endif } }
private void Run( #if WITH_SERVICE_MODEL System.ServiceModel.Dispatcher.ExceptionHandler eh = null #endif ) { try { while (_grabState == GrabState.Running || _grabState == GrabState.Pause) { if (_grabState == GrabState.Pause) { _pauseEvent.WaitOne(); } else if (IntPtr.Zero.Equals(_ptr) || !Grab()) { //capture has been released, or //no more frames to grab, this is the end of the stream. //We should stop. _grabState = GrabState.Stopping; } } } catch (Exception e) { #if WITH_SERVICE_MODEL if (eh != null && eh.HandleException(e)) { return; } #endif throw new Exception("Capture error", e); } finally { _grabState = GrabState.Stopped; } }
internal static bool HandleTransportExceptionHelper(Exception exception) { if (exception == null) { throw Fx.AssertAndThrow("Null exception passed to HandleTransportExceptionHelper."); } System.ServiceModel.Dispatcher.ExceptionHandler transportExceptionHandler = TransportExceptionHandler; if (transportExceptionHandler == null) { return(false); } try { if (!transportExceptionHandler.HandleException(exception)) { return(false); } } catch (Exception exception2) { if (Fx.IsFatal(exception2)) { throw; } if (DiagnosticUtility.ShouldTraceError) { DiagnosticUtility.ExceptionUtility.TraceHandledException(exception2, TraceEventType.Error); } return(false); } if (DiagnosticUtility.ShouldTraceError) { DiagnosticUtility.ExceptionUtility.TraceHandledException(exception, TraceEventType.Error); } return(true); }
/// <summary> /// Start the grab process in a separate thread. Once started, use the ImageGrabbed event handler and RetrieveGrayFrame/RetrieveBgrFrame to obtain the images. /// </summary> /// <param name="eh">An exception handler. If provided, it will be used to handle exception in the capture thread.</param> public void Start(System.ServiceModel.Dispatcher.ExceptionHandler eh = null)
public HandlerWrapper(System.ServiceModel.Dispatcher.ExceptionHandler handler) { this.handler = handler; }