.NET Framework Class Library
ExecutionContext..::.Run Method

Runs a method in a specified execution context on the current thread.

Namespace:  System.Threading
Assembly:  mscorlib (in mscorlib.dll)
Syntax

Visual Basic (Declaration)
<SecurityPermissionAttribute(SecurityAction.LinkDemand, Flags := SecurityPermissionFlag.Infrastructure)> _
Public Shared Sub Run ( _
    executionContext As ExecutionContext, _
    callback As ContextCallback, _
    state As Object _
)
Visual Basic (Usage)
Dim executionContext As ExecutionContext
Dim callback As ContextCallback
Dim state As Object

ExecutionContext.Run(executionContext, callback, _
    state)
C#
[SecurityPermissionAttribute(SecurityAction.LinkDemand, Flags = SecurityPermissionFlag.Infrastructure)]
public static void Run(
    ExecutionContext executionContext,
    ContextCallback callback,
    Object state
)
Visual C++
[SecurityPermissionAttribute(SecurityAction::LinkDemand, Flags = SecurityPermissionFlag::Infrastructure)]
public:
static void Run(
    ExecutionContext^ executionContext, 
    ContextCallback^ callback, 
    Object^ state
)
JScript
public static function Run(
    executionContext : ExecutionContext, 
    callback : ContextCallback, 
    state : Object
)

Parameters

executionContext
Type: System.Threading..::.ExecutionContext
The ExecutionContext to set.
callback
Type: System.Threading..::.ContextCallback
A ContextCallback delegate that represents the method to be run in the provided execution context.
state
Type: System..::.Object
The object to pass to the callback method.
Exceptions

ExceptionCondition
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.

Remarks

The execution context is returned to its previous state when the method completes.

Examples

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.

Visual Basic
' 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
C#
// 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();
}
Visual C++
// 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();
};
.NET Framework Security

Platforms

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.
Version Information

.NET Framework

Supported in: 3.5, 3.0, 2.0
See Also

Reference

Tags :


Page view tracker