ThreadPool.UnsafeQueueUserWorkItem ThreadPool.UnsafeQueueUserWorkItem ThreadPool.UnsafeQueueUserWorkItem ThreadPool.UnsafeQueueUserWorkItem Method

Definition

Overloads

UnsafeQueueUserWorkItem(IThreadPoolWorkItem, Boolean) UnsafeQueueUserWorkItem(IThreadPoolWorkItem, Boolean) UnsafeQueueUserWorkItem(IThreadPoolWorkItem, Boolean) UnsafeQueueUserWorkItem(IThreadPoolWorkItem, Boolean)
UnsafeQueueUserWorkItem(WaitCallback, Object) UnsafeQueueUserWorkItem(WaitCallback, Object) UnsafeQueueUserWorkItem(WaitCallback, Object) UnsafeQueueUserWorkItem(WaitCallback, Object)

Queues the specified delegate to the thread pool, but does not propagate the calling stack to the worker thread.

UnsafeQueueUserWorkItem<TState>(Action<TState>, TState, Boolean) UnsafeQueueUserWorkItem<TState>(Action<TState>, TState, Boolean) UnsafeQueueUserWorkItem<TState>(Action<TState>, TState, Boolean) UnsafeQueueUserWorkItem<TState>(Action<TState>, TState, Boolean)

Queues a method specified by an Action<T> delegate for execution, and specifies an object containing data to be used by the method. The method executes when a thread pool thread becomes available.

UnsafeQueueUserWorkItem(IThreadPoolWorkItem, Boolean) UnsafeQueueUserWorkItem(IThreadPoolWorkItem, Boolean) UnsafeQueueUserWorkItem(IThreadPoolWorkItem, Boolean) UnsafeQueueUserWorkItem(IThreadPoolWorkItem, Boolean)

public:
 static bool UnsafeQueueUserWorkItem(System::Threading::IThreadPoolWorkItem ^ callBack, bool preferLocal);
public static bool UnsafeQueueUserWorkItem (System.Threading.IThreadPoolWorkItem callBack, bool preferLocal);
static member UnsafeQueueUserWorkItem : System.Threading.IThreadPoolWorkItem * bool -> bool
Public Shared Function UnsafeQueueUserWorkItem (callBack As IThreadPoolWorkItem, preferLocal As Boolean) As Boolean

Parameters

Returns

UnsafeQueueUserWorkItem(WaitCallback, Object) UnsafeQueueUserWorkItem(WaitCallback, Object) UnsafeQueueUserWorkItem(WaitCallback, Object) UnsafeQueueUserWorkItem(WaitCallback, Object)

Queues the specified delegate to the thread pool, but does not propagate the calling stack to the worker thread.

public:
 static bool UnsafeQueueUserWorkItem(System::Threading::WaitCallback ^ callBack, System::Object ^ state);
[System.Security.SecurityCritical]
public static bool UnsafeQueueUserWorkItem (System.Threading.WaitCallback callBack, object state);
static member UnsafeQueueUserWorkItem : System.Threading.WaitCallback * obj -> bool
Public Shared Function UnsafeQueueUserWorkItem (callBack As WaitCallback, state As Object) As Boolean

Parameters

callBack
WaitCallback WaitCallback WaitCallback WaitCallback

A WaitCallback that represents the delegate to invoke when a thread in the thread pool picks up the work item.

state
Object Object Object Object

The object that is passed to the delegate when serviced from the thread pool.

Returns

true if the method succeeds; OutOfMemoryException is thrown if the work item could not be queued.

Exceptions

The caller does not have the required permission.

Remarks

Unlike the QueueUserWorkItem method, UnsafeQueueUserWorkItem does not propagate the calling stack to the worker thread. This allows code to lose the calling stack and thereby to elevate its security privileges.

Caution

Using UnsafeQueueUserWorkItem could inadvertently open up a security hole. Code access security bases its permission checks on the permissions of all the callers on the stack. When work is queued on a thread pool thread using UnsafeQueueUserWorkItem, the stack of the thread pool thread will not have the context of the actual callers. Malicious code might be able exploit this to avoid permission checks.

Security

SecurityCriticalAttribute
Requires full trust for the immediate caller. This member cannot be used by partially trusted or transparent code.

See also

UnsafeQueueUserWorkItem<TState>(Action<TState>, TState, Boolean) UnsafeQueueUserWorkItem<TState>(Action<TState>, TState, Boolean) UnsafeQueueUserWorkItem<TState>(Action<TState>, TState, Boolean) UnsafeQueueUserWorkItem<TState>(Action<TState>, TState, Boolean)

Queues a method specified by an Action<T> delegate for execution, and specifies an object containing data to be used by the method. The method executes when a thread pool thread becomes available.

public:
generic <typename TState>
 static bool UnsafeQueueUserWorkItem(Action<TState> ^ callBack, TState state, bool preferLocal);
public static bool UnsafeQueueUserWorkItem<TState> (Action<TState> callBack, TState state, bool preferLocal);
static member UnsafeQueueUserWorkItem : Action<'State> * 'State * bool -> bool
Public Shared Function UnsafeQueueUserWorkItem(Of TState) (callBack As Action(Of TState), state As TState, preferLocal As Boolean) As Boolean

Type Parameters

TState

The type of elements of state.

Parameters

callBack
Action<TState>

A delegate representing the method to execute.

state

An object containing data to be used by the method.

preferLocal
Boolean Boolean Boolean Boolean

true to execute in the local threadpool; false to execute in the global thread pool.

Returns

true if the method is successfully queued; NotSupportedException is thrown if the work item could not be queued.

Applies to