ThreadHelper Class

Provides a generic dispatcher helper to ensure that a method is invoked on the application's main thread.

Inheritance Hierarchy


Namespace:  Microsoft.VisualStudio.Shell
Assembly:  Microsoft.VisualStudio.Shell.10.0 (in Microsoft.VisualStudio.Shell.10.0.dll)


Public MustInherit Class ThreadHelper
public abstract class ThreadHelper
public ref class ThreadHelper abstract
type ThreadHelper =  class end
public abstract class ThreadHelper

The ThreadHelper type exposes the following members.


  Name Description
Protected method ThreadHelper Initializes a new instance of ThreadHelper.



  Name Description
Public propertyStatic member Generic Gets a generic ThreadHelper.



  Name Description
Public method Equals Determines whether the specified Object is equal to the current Object. (Inherited from Object.)
Protected method Finalize Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.)
Public method GetHashCode Serves as a hash function for a particular type. (Inherited from Object.)
Protected method GetInvocationWrapper Gets the invocation wrapper.
Public method GetType Gets the Type of the current instance. (Inherited from Object.)
Public method Invoke(Action) Calls an action on the UI thread.
Public method Invoke<TResult>(Func<TResult>)
Protected method MemberwiseClone Creates a shallow copy of the current Object. (Inherited from Object.)
Public method ToString Returns a string that represents the current object. (Inherited from Object.)



We use the current application's dispatcher for convenient identification of the main thread. Note that this means that the application object must be initialized by the window manager.

However, DispatcherOperation objects are not used, because they are not compatible with RPC. For example, if the UI thread is in the middle of an RPC call, and code must run on the UI thread, then DispatcherOperation objects will not get through. This is because DispatcherOperation objects are initiated by posting a message to the UI thread, and the UI thread must dispatch that message. If the UI thread is making an RPC call, these messages will not be removed from the queue. The standard OLE message filter processes only a limited set of messages from the queue.

By going through the SVsUIThreadInvokerPrivate service, the operation becomes a COM call on the UI thread. This operation is allowed through the Visual Studio message filter if it is part of the same logical call, since the message filter will see it as a nested call and may not reject it.

Thread Safety

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

See Also


Microsoft.VisualStudio.Shell Namespace