I made a TV-Player in c# using directshowlib-2005. now I made a method to search for available channels.
I want this method to run in a different thread so my GUI won't freeze, but I get an error when I try to set the channel in the method. It can't find the IAMTVTuner interface in my graph, altough I know it's there.
If I don't use a different thread, the method works just fine (but my GUI freezes for a while)
I know it has to do something with apartments, but is there a way I can acces that interface in a different thread then the thread where created my graph in?
This problem is because some com classes or interfaces like in the
DirectShowLib
should be just accessed from the same thread that it was created on. So the solution to this problem is to implement ISynchronizeInvoke "System.ComponentModel.ISynchronizeInvoke".For example if you need to access methods in the class named
Media
that uses internally some classes or methods from theDirectshowLib
in multithreading mode, you have to check if invoke required by usingInvokeRequired
and if true you have to access it viaInvoke
method. To demonstrate how to implementISynchronizeInvoke
interface here is a snippet from a code that I develop some time ago in C# 2.0