ThreadHelper Class

 

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

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

System.Object
  Microsoft.VisualStudio.Shell.ThreadHelper

public abstract class ThreadHelper

NameDescription
System_CAPS_protmethodThreadHelper()

Initializes a new instance of ThreadHelper.

NameDescription
System_CAPS_pubpropertySystem_CAPS_staticGeneric

Gets a generic ThreadHelper.

System_CAPS_pubpropertySystem_CAPS_staticJoinableTaskContext

Gets the singleton JoinableTaskContext instance for Visual Studio.

System_CAPS_pubpropertySystem_CAPS_staticJoinableTaskFactory

Gets the joinable task factory for Visual Studio.

NameDescription
System_CAPS_pubmethodBeginInvoke(Action)

Schedules an action for execution on the UI thread asynchronously.

System_CAPS_pubmethodBeginInvoke(DispatcherPriority, Action)

Schedules an action for execution on the UI thread asynchronously.

System_CAPS_pubmethodSystem_CAPS_staticCheckAccess()

Determines whether the call is being made on the UI thread.

System_CAPS_pubmethodEquals(Object)

(Inherited from Object.)

System_CAPS_protmethodFinalize()

(Inherited from Object.)

System_CAPS_pubmethodGetHashCode()

(Inherited from Object.)

System_CAPS_protmethodGetInvocationWrapper()

Gets the invocation wrapper.

System_CAPS_pubmethodGetType()

(Inherited from Object.)

System_CAPS_pubmethodInvoke(Action)

Calls an action on the UI thread, re-entering (if necessary) any code already executing on the UI thread.

System_CAPS_pubmethodInvoke<TResult>(Func<TResult>)

Evaluate a function on the UI thread.

System_CAPS_pubmethodInvokeAsync(Action, Func<Boolean>)

Makes the RPC call to invoke the action like Invoke method but on the background thread. Since it is on the background thread, it doesn't block until the RPC call is served. If the RPC call fails, it retries until the onRpcCallFailed returns true. This method is also different from the BeginInvoke method, which uses the UI thread dispatcher, and it may not be in a state to process the request immediately (for example, it can be in a pumping wait).

System_CAPS_protmethodMemberwiseClone()

(Inherited from Object.)

System_CAPS_pubmethodSystem_CAPS_staticThrowIfNotOnUIThread(String)

Determines whether the call is being made on the UI thread, and throws COMException(RPC_E_WRONG_THREAD) if it is not.

System_CAPS_pubmethodSystem_CAPS_staticThrowIfOnUIThread(String)

Determines whether the call is being made on the UI thread ,and throws COMException(RPC_E_WRONG_THREAD) if it is.

System_CAPS_pubmethodToString()

(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 a private 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.

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

Return to top
Show: