Share via


ThreadHelper Class

Provide a generic dispatcher helper ensure that a method is invoked on the Application's main thread.

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

Syntax

‘선언
Public MustInherit Class ThreadHelper
‘사용 방법
Dim instance As ThreadHelper
public abstract class ThreadHelper
public ref class ThreadHelper abstract
[<AbstractClassAttribute>]
type ThreadHelper =  class end
public abstract class ThreadHelper

Remarks

We use the current Application's Dispatcher for convenient identification of the main thread. Note that this means that the Application's instance must be initialized.

Currently, the WindowManager initializes it.

However, we don't use DispatcherOperation because they are not RPC friendly. For example, if the UI thread is in the middle of an RPC call, and we need to run code on the UI thread, then DispatcherOperations will not get through. This is because DispatcherOperations are initiated by posting a message to the UI thread and the UI thread needs to 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 and even the Visual Studio message filter ignores most others.

By going through the UIThreadInvokerPrivate service, the operation becomes a COM call on the UI thread. This operation will be allowed through our message filter IF it is part of the same logical call - the message filter will see it as a "nested call" and may not reject it.

Inheritance Hierarchy

System.Object
  Microsoft.VisualStudio.Shell.ThreadHelper

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

Reference

ThreadHelper Members

Microsoft.VisualStudio.Shell Namespace