Share via


Context::Block Method

Blocks the current context.

_CRTIMP static void __cdecl Block();

Remarks

This method will result in the process' default scheduler being created and/or attached to the calling context if there is no scheduler currently associated with the calling context.

If the calling context is running on a virtual processor, the virtual processor will find another runnable context to execute or may potentially create a new one.

Once the Block method has been called or will be called, you must pair it with a call to the Unblock method from another execution context in order for it to run again. Be aware that there is a critical period between the point where your code publishes its context for another thread to be able to call the Unblock method and the point where the actual method call to Block is made. During this period, it is imperative that you not call any method which may in turn block and unblock for its own reasons (e.g.: acquiring a lock). Calls to the Block and Unblock method do not track the reason for the blocking and unblocking. Only one object should have ownership of a Block-Unblock pair.

This method may throw a variety of exceptions, including scheduler_resource_allocation_error.

Requirements

Header: concrt.h

Namespace: Concurrency

See Also

Reference

Context Class

Context::Unblock Method

Concepts

Task Scheduler (Concurrency Runtime)