Runs a method in a specified execution context on the current thread.
Namespace:
System.Threading
Assembly:
mscorlib (in mscorlib.dll)
Visual Basic (Declaration)
<SecurityPermissionAttribute(SecurityAction.LinkDemand, Flags := SecurityPermissionFlag.Infrastructure)> _
Public Shared Sub Run ( _
executionContext As ExecutionContext, _
callback As ContextCallback, _
state As Object _
)
Dim executionContext As ExecutionContext
Dim callback As ContextCallback
Dim state As Object
ExecutionContext.Run(executionContext, callback, _
state)
[SecurityPermissionAttribute(SecurityAction.LinkDemand, Flags = SecurityPermissionFlag.Infrastructure)]
public static void Run(
ExecutionContext executionContext,
ContextCallback callback,
Object state
)
[SecurityPermissionAttribute(SecurityAction::LinkDemand, Flags = SecurityPermissionFlag::Infrastructure)]
public:
static void Run(
ExecutionContext^ executionContext,
ContextCallback^ callback,
Object^ state
)
public static function Run(
executionContext : ExecutionContext,
callback : ContextCallback,
state : Object
)
| Exception | Condition |
|---|
| InvalidOperationException |
executionContext is nullNothingnullptra null reference (Nothing in Visual Basic). -or-
executionContext was not acquired through a capture operation. -or-
executionContext has already been used as the argument to a Run call. |
The execution context is returned to its previous state when the method completes.
The following code example demonstrates the use of the Run method to execute a callback in a captured execution context. This code example is part of a larger example provided for the ExecutionContext class.
' Use the Run method to execute DemandPermission in
' the captured context, where Deny is active. The
' demand fails.
ExecutionContext.Run(eC, AddressOf CallbackInContext, Nothing)
...
Shared Sub CallbackInContext(ByVal state As Object)
' The state is not used in this example.
DemandPermission()
End Sub
// Use the Run method to execute DemandPermission in
// the captured context, where Deny is active. The
// demand fails.
ExecutionContext.Run(eC, CallbackInContext, null);
...
static void CallbackInContext(object state)
{
// The state is not used in this example.
DemandPermission();
}
// Use the Run method to execute DemandPermission in
// the captured context, where Deny is active. The
// demand fails.
ContextCallback^ callback = gcnew ContextCallback(&CallbackInContext);
ExecutionContext::Run(eC, callback, nullptr);
...
void CallbackInContext(Object^ state)
{
// The state is not used in this example.
DemandPermission();
};
Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98
The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
.NET Framework
Supported in: 3.5, 3.0, 2.0
Reference