Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>This problem is because some com classes or interfaces like in the <code>DirectShowLib</code> should be just accessed from <strong>the same thread that it was created on</strong>. So the solution to this problem is to implement <a href="http://msdn.microsoft.com/en-us/library/system.componentmodel.isynchronizeinvoke.aspx" rel="nofollow">ISynchronizeInvoke</a> "System.ComponentModel.ISynchronizeInvoke".</p> <p>For example if you need to access methods in the class named <code>Media</code> that uses internally some classes or methods from the <code>DirectshowLib</code> in multithreading mode, you have to check if invoke required by using <code>InvokeRequired</code> and if true you have to access it via <code>Invoke</code> method. To demonstrate how to implement <code>ISynchronizeInvoke</code> interface here is a snippet from a code that I develop some time ago in C# 2.0</p> <pre><code>public abstract class Media : ISynchronizeInvoke { //.... private readonly System.Threading.SynchronizationContext _currentContext = System.Threading.SynchronizationContext.Current; private readonly System.Threading.Thread _mainThread = System.Threading.Thread.CurrentThread; private readonly object _invokeLocker = new object(); //.... #region ISynchronizeInvoke Members public bool InvokeRequired { get { return System.Threading.Thread.CurrentThread.ManagedThreadId != this._mainThread.ManagedThreadId; } } /// &lt;summary&gt; /// This method is not supported! /// &lt;/summary&gt; /// &lt;param name="method"&gt;&lt;/param&gt; /// &lt;param name="args"&gt;&lt;/param&gt; /// &lt;returns&gt;&lt;/returns&gt; [Obsolete("This method is not supported!", true)] public IAsyncResult BeginInvoke(Delegate method, object[] args) { throw new NotSupportedException("The method or operation is not implemented."); } /// &lt;summary&gt; /// This method is not supported! /// &lt;/summary&gt; /// &lt;param name="method"&gt;&lt;/param&gt; /// &lt;param name="args"&gt;&lt;/param&gt; /// &lt;returns&gt;&lt;/returns&gt; [Obsolete("This method is not supported!", true)] public object EndInvoke(IAsyncResult result) { throw new NotSupportedException("The method or operation is not implemented."); } public object Invoke(Delegate method, object[] args) { if (method == null) { throw new ArgumentNullException("method"); } lock (_invokeLocker) { object objectToGet = null; SendOrPostCallback invoker = new SendOrPostCallback( delegate(object data) { objectToGet = method.DynamicInvoke(args); }); _currentContext.Send(new SendOrPostCallback(invoker), method.Target); return objectToGet; } } public object Invoke(Delegate method) { return Invoke(method, null); } #endregion//ISynchronizeInvoke Members } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload