Share via


ThreadHelper.ThrowIfOnUIThread(String) Method

Definition

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

 static void ThrowIfOnUIThread(std::wstring const & callerMemberName = "");
public static void ThrowIfOnUIThread (string callerMemberName = "");
static member ThrowIfOnUIThread : string -> unit
Public Shared Sub ThrowIfOnUIThread (Optional callerMemberName As String = "")

Parameters

callerMemberName
String

Optional name of caller if a Debug Assert is desired if on the UI thread.

Exceptions

COMException

Thrown with RPC_E_WRONG_THREAD when called on any thread other than the main UI thread.

Remarks

The exception thrown from this method is not expected to be caught and handled by anyone. It is meant to cause the caller to fail, and get their attention that they should not be invoking the throwing code on the UI thread. This is analogous to throwing ArgumentException when the caller simply did not understand the contract of the method they were calling.

Applies to