Export (0) Print
Expand All

SecurityContext.Run Method

Note: This method is new in the .NET Framework version 2.0.

Runs the specified method in the specified security context on the current thread.

Namespace: System.Security
Assembly: mscorlib (in mscorlib.dll)

public static void Run (
	SecurityContext securityContext,
	ContextCallback callback,
	Object state
)
public static void Run (
	SecurityContext securityContext, 
	ContextCallback callback, 
	Object state
)
public static function Run (
	securityContext : SecurityContext, 
	callback : ContextCallback, 
	state : Object
)

Parameters

securityContext

The SecurityContext to set.

callback

The ContextCallback delegate that represents the method to run in the specified security context.

state

The object to pass to the callback method.

Exception typeCondition

InvalidOperationException

securityContext is a null reference (Nothing in Visual Basic).

-or-

securityContext was not acquired through a capture operation

-or-

securityContext has already been used as the argument to a Run method call.

The security context for the current thread is returned to its previous state when the method call is complete.

The following code example shows how to use the Run method to execute a method in a specified security context.

using System;
using System.Security;
using System.Threading;

class Test
{
    static void Main()
    {
        SecurityContext.Run(SecurityContext.Capture(), 
            new ContextCallback(Callback), "Hello world.");
    }
    static void Callback(object o)
    {
        Console.WriteLine(o);
    }
}

Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.

.NET Framework

Supported in: 2.0

Community Additions

ADD
Show:
© 2014 Microsoft