View Full Version : Exception when I unplug the camera during live video

June 24, 2013, 17:17:56
Running a DFK 72AUC02-F in a WPF application.

I handle the live video display myself, the ICImagingControl is not placed on a form/window but New'ed in code.

When in live video mode, if I pull out the plug from the camera I get the following exception generated:-

System.InvalidOperationException was unhandled
Message=Invoke or BeginInvoke cannot be called on a control until the window handle has been created.
at System.Windows.Forms.Control.MarshaledInvoke(Contr ol caller, Delegate method, Object[] args, Boolean synchronous)
at System.Windows.Forms.Control.BeginInvoke(Delegate method, Object[] args)
at System.Windows.Forms.Control.BeginInvoke(Delegate method)
at TIS.Imaging.ListenerProxy.DeviceLost()
at TIS.Imaging.ListenerFwd.deviceLost(ListenerFwd* , Grabber* caller)

It looks like a TIS background thread is trying to invoke onto the GUI thread but the ICImagingControl is not bound to a window handle. I don't have any way of catching this exception. I've tried adding a AppDomain.UnhandledException but I cannot stop the application closing down. I don't see how this is different to the ImageAvailable event which does a similar thing with absolutely no problems.


Michael Kirmse
June 25, 2013, 11:02:33
Hello Jerry,

How did you implement the DeviceLost event?

June 25, 2013, 11:10:59
The first thing I did was comment out my DeviceLost event handler but it made no difference and I still see this exception. The exception occurs before my code is called inside one of the TIS threads. I use the ImageAvailable event with no problem but the DeviceLost must be implemented differently. I don't want to have to close down the application simply because the cable is unplugged, but I can't stop it.

Michael Kirmse
June 25, 2013, 11:21:06
Can you provide a small code sample that reproduces the issue?

Michael Kirmse
June 25, 2013, 11:41:50
I have tried a bit with WPF. This code:

namespace WPFTest
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
ICImagingControl _icImagingControl1;

public MainWindow()
this.Loaded += MainWindow_Loaded;

void MainWindow_Loaded(object sender, RoutedEventArgs e)
_icImagingControl1 = new ICImagingControl();
_icImagingControl1.DeviceLost += (s, ev) =>

implements a DeviceLost event that works fine for me.

June 25, 2013, 12:51:17
I am trying to select the camera without using the ShowDeviceSettingsDialog.

So in your code change:



_icImagingControl1.Device = _icImagingControl1.Devices[0];

Once the window is up, pull the plug. That breaks things for me.

Michael Kirmse
June 25, 2013, 14:28:18
Please set the DeviceLostExecution mode of you ImagingControl to MultiThreaded. To do this, include this line in your code:

_icImagingControl1.DeviceLostExecutionMode = EventExecutionMode.MultiThreaded;

That should fix the problem.

June 25, 2013, 15:24:35
Thanks, that fixed it.