ThreadPool.UnsafeQueueUserWorkItem(WaitCallback, Object) ThreadPool.UnsafeQueueUserWorkItem(WaitCallback, Object) ThreadPool.UnsafeQueueUserWorkItem(WaitCallback, Object) ThreadPool.UnsafeQueueUserWorkItem(WaitCallback, Object) Method

Definition

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.

Applies to

See Also