How does "Threadpool.Unsafequeueuserworkitem" work?

Asked

Viewed 61 times

2

I’ve done some research but I’m not finding a more didactic explanation, since I have no experience with threads.

1 answer

1


Thead Pool:

Provides a pool of threads that can be used to perform tasks, post work items, process asynchronous I/O, wait on behalf of other threads, and process timers.

Utilizing:

You should use threads when you want your system’s main thread not to be stuck waiting for a time-consuming task to be performed.

Unsafequeueuserworkitem:

Unlike the method QueueUserWorkItem, UnsafeQueueUserWorkItem does not propagate the stack of calls to the working thread. This allows the code to lose the call stack and thus raise its security privileges.

Remarks:

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

Reference: Unsafequeueuserworkitem Threadpool

Browser other questions tagged

You are not signed in. Login or sign up in order to post.