ThreadHelper Class

Definition

Provide a generic dispatcher helper ensure that a method is invoked on the Application's main thread. 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.

public ref class ThreadHelper abstract
[Windows::Foundation::Metadata::WebHostHidden]
public ref class ThreadHelper abstract
[Windows::Foundation::Metadata::WebHostHidden]
class ThreadHelper abstract
public abstract class ThreadHelper
type ThreadHelper = class
Public MustInherit Class ThreadHelper
Inheritance
ThreadHelper

Constructors

ThreadHelper()

Initializes a new instance of ThreadHelper.

Properties

Generic

Gets a generic ThreadHelper.

JoinableTaskContext

Gets the singleton JoinableTaskContext instance for Visual Studio.

JoinableTaskFactory

Gets the joinable task factory for Visual Studio.

Methods

BeginInvoke(Action)

Schedule an action for execution on the UI thread asynchronously.

BeginInvoke(DispatcherPriority, Action)

Schedule an action for execution on the UI thread asynchronously.

CheckAccess()

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

GetInvocationWrapper()

Derived classes must implement the GetInvocationWrapper method to implement a a disposable object that will wrap the called method. This may be null.

ThrowIfNotOnUIThread(String)

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

ThrowIfOnUIThread(String)

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

Applies to