So, basically, I just woke up one morning, got to work, and stared at the code and went, "Wait, I know why this isn't working...". It is a threading issue. The initial graphs I was creating were on a different thread than the graphs I was trying to create later. That's why it only happens when I recreate the graphs.
I was also having a problem with IVideoWindow's put_Owner
method when the device is plugged in after the application has already started. In this case, the device wasn't unplugged while executing, and put_Owner would freeze/deadlock trying to that method.
Overall, I have a thread that is detecting when a device is unplugged/plugged in using DsDevice.GetDevicesOfCat(FilterCategory.VideoInputDevice)
. So, when I go to create these graphs, they are not on the main UI thread where the other graphs were originally created. To solve this, I have my class that is handling the devices take in an Action<Action> invoker
which allows you to provide a method wrapper. In this case, I pass it Control.Invoke
of the WinForms form so that the calls on the device monitoring thread are wrapped by this invoker method within the UI thread. Completely solved my graph creation issues.
I am HIGHLY SURPRISED no one else ran into this before. I couldn't find anyone else mentioning threading when discussing issues related to this error. Very strange.