WindowsIdentity.RunImpersonatedAsync Method

Definition

Overloads

RunImpersonatedAsync(SafeAccessTokenHandle, Func<Task>)

Runs the specified asynchronous action as the impersonated Windows identity.

RunImpersonatedAsync<T>(SafeAccessTokenHandle, Func<Task<T>>)

Runs the specified asynchronous action as the impersonated Windows identity.

RunImpersonatedAsync(SafeAccessTokenHandle, Func<Task>)

Runs the specified asynchronous action as the impersonated Windows identity.

C#
public static System.Threading.Tasks.Task RunImpersonatedAsync(Microsoft.Win32.SafeHandles.SafeAccessTokenHandle safeAccessTokenHandle, Func<System.Threading.Tasks.Task> func);

Parameters

safeAccessTokenHandle
SafeAccessTokenHandle

The handle of the impersonated Windows identity.

func
Func<Task>

The function to run.

Returns

A task that represents the asynchronous operation of the provided Func<TResult>.

Applies to

.NET 9 and other versions
Product Versions
.NET 6, 7, 8, 9
.NET Standard 2.0 (package-provided)
Windows Desktop 5

RunImpersonatedAsync<T>(SafeAccessTokenHandle, Func<Task<T>>)

Runs the specified asynchronous action as the impersonated Windows identity.

C#
public static System.Threading.Tasks.Task<T> RunImpersonatedAsync<T>(Microsoft.Win32.SafeHandles.SafeAccessTokenHandle safeAccessTokenHandle, Func<System.Threading.Tasks.Task<T>> func);

Type Parameters

T

The type of the object to return.

Parameters

safeAccessTokenHandle
SafeAccessTokenHandle

The handle of the impersonated Windows identity.

func
Func<Task<T>>

The function to run.

Returns

Task<T>

A task that represents the asynchronous operation of func.

Applies to

.NET 9 and other versions
Product Versions
.NET 6, 7, 8, 9
.NET Standard 2.0 (package-provided)
Windows Desktop 5