Click to Rate and Give Feedback
MSDN
MSDN Library
.NET Development
.NET Framework 3.5
 Run Method

  Switch on low bandwidth view
This page is specific to
Microsoft Visual Studio 2008/.NET Framework 3.5

Other versions are also available for the following:
.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)
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.
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.

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.

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();
};

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
Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
Processing
© 2009 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Page view tracker