void _grabber_OnFrame(Parsley.Core.BuildingBlocks.FrameGrabber fg, Emgu.CV.Image<Emgu.CV.Structure.Bgr, byte> img) { // Note: This method is called from the frame-grabber's thread loop. // The framegrabber holds a Breath on the camera to ensure that the camera object remains // alive during this callback. The camera object is a SharedResource, meaning that any // invocation to Dispose will block until all Breaths on the camera are released. Suppose // The thread that owns the picture box has called dispose and blocks. The callback here is called // and invoke is used. Invoke executes the delegate on thread that owns this control, which is the one // that is already blocked. This leads to a deadlock. That is why we use BeginInvoke, which executes // the delegate on the GUI thread associated with this control. if (_can_invoke) { Rectangle client = this.ClientRectangle; Emgu.CV.Image<Emgu.CV.Structure.Bgr, byte> img_copy = img.Resize(client.Width, client.Height, _interpolation); this.BeginInvoke(new MethodInvoker(delegate { // Update image Emgu.CV.IImage prev = _picture_box.Image; _picture_box.Image = img_copy; if (prev != null) { prev.Dispose(); } })); } }