Class AsyncPatterns
Provides a generic way to support different types of design patterns and practices with small utility methods scoped to Task.
public sealed class AsyncPatterns
  - Inheritance
 - 
      
      AsyncPatterns
 
Properties
Use
Gets the singleton instance of the AsyncPatterns functionality allowing for extensions methods like: AsyncPatterns.Use.SomeIngeniousMethod().
public static AsyncPatterns Use { get; }
  Property Value
- AsyncPatterns
 The singleton instance of the AsyncPatterns functionality.
Methods
SafeInvokeAsync<TResult>(Func<TResult>, Func<TResult, CancellationToken, Task<TResult>>, Func<Exception, CancellationToken, Task>, CancellationToken)
Provides a generic way to abide the rule description of CA2000 (Dispose objects before losing scope).
public static Task<TResult> SafeInvokeAsync<TResult>(Func<TResult> initializer, Func<TResult, CancellationToken, Task<TResult>> tester, Func<Exception, CancellationToken, Task> catcher = null, CancellationToken ct = default) where TResult : class, IDisposable
  Parameters
initializerFunc<TResult>The function delegate that initializes an object implementing the IDisposable interface.
testerFunc<TResult, CancellationToken, Task<TResult>>The function delegate that is used to ensure that operations performed on
TResultabides CA2000.catcherFunc<Exception, CancellationToken, Task>The function delegate that will handle any exceptions that might have been thrown by
tester.ctCancellationTokenThe token to monitor for cancellation requests. The default value is None.
Returns
- Task<TResult>
 A task that represents the asynchronous operation. The task result contains the return value of the function delegate
initializerif the operations succeeded; otherwise null if the operation failed.
Type Parameters
TResultThe type of the return value of the function delegate
initializer.
SafeInvokeAsync<T, TResult>(Func<TResult>, Func<TResult, T, CancellationToken, Task<TResult>>, T, Func<Exception, T, CancellationToken, Task>, CancellationToken)
Provides a generic way to abide the rule description of CA2000 (Dispose objects before losing scope).
public static Task<TResult> SafeInvokeAsync<T, TResult>(Func<TResult> initializer, Func<TResult, T, CancellationToken, Task<TResult>> tester, T arg, Func<Exception, T, CancellationToken, Task> catcher = null, CancellationToken ct = default) where TResult : class, IDisposable
  Parameters
initializerFunc<TResult>The function delegate that initializes an object implementing the IDisposable interface.
testerFunc<TResult, T, CancellationToken, Task<TResult>>The function delegate that is used to ensure that operations performed on
TResultabides CA2000.argTThe parameter of the function delegate
testerand delegatecatcher.catcherFunc<Exception, T, CancellationToken, Task>The function delegate that will handle any exceptions that might have been thrown by
tester.ctCancellationTokenThe token to monitor for cancellation requests. The default value is None.
Returns
- Task<TResult>
 A task that represents the asynchronous operation. The task result contains the return value of the function delegate
initializerif the operations succeeded; otherwise null if the operation failed.
Type Parameters
TThe type of the parameter of the function delegate
testerand delegatecatcher.TResultThe type of the return value of the function delegate
initializer.
SafeInvokeAsync<T1, T2, TResult>(Func<TResult>, Func<TResult, T1, T2, CancellationToken, Task<TResult>>, T1, T2, Func<Exception, T1, T2, CancellationToken, Task>, CancellationToken)
Provides a generic way to abide the rule description of CA2000 (Dispose objects before losing scope).
public static Task<TResult> SafeInvokeAsync<T1, T2, TResult>(Func<TResult> initializer, Func<TResult, T1, T2, CancellationToken, Task<TResult>> tester, T1 arg1, T2 arg2, Func<Exception, T1, T2, CancellationToken, Task> catcher = null, CancellationToken ct = default) where TResult : class, IDisposable
  Parameters
initializerFunc<TResult>The function delegate that initializes an object implementing the IDisposable interface.
testerFunc<TResult, T1, T2, CancellationToken, Task<TResult>>The function delegate that is used to ensure that operations performed on
TResultabides CA2000.arg1T1The first parameter of the function delegate
testerand delegatecatcher.arg2T2The second parameter of the function delegate
testerand delegatecatcher.catcherFunc<Exception, T1, T2, CancellationToken, Task>The function delegate that will handle any exceptions that might have been thrown by
tester.ctCancellationTokenThe token to monitor for cancellation requests. The default value is None.
Returns
- Task<TResult>
 A task that represents the asynchronous operation. The task result contains the return value of the function delegate
initializerif the operations succeeded; otherwise null if the operation failed.
Type Parameters
T1The type of the first parameter of the function delegate
testerand delegatecatcher.T2The type of the second parameter of the function delegate
testerand delegatecatcher.TResultThe type of the return value of the function delegate
initializer.
SafeInvokeAsync<T1, T2, T3, TResult>(Func<TResult>, Func<TResult, T1, T2, T3, CancellationToken, Task<TResult>>, T1, T2, T3, Func<Exception, T1, T2, T3, CancellationToken, Task>, CancellationToken)
Provides a generic way to abide the rule description of CA2000 (Dispose objects before losing scope).
public static Task<TResult> SafeInvokeAsync<T1, T2, T3, TResult>(Func<TResult> initializer, Func<TResult, T1, T2, T3, CancellationToken, Task<TResult>> tester, T1 arg1, T2 arg2, T3 arg3, Func<Exception, T1, T2, T3, CancellationToken, Task> catcher = null, CancellationToken ct = default) where TResult : class, IDisposable
  Parameters
initializerFunc<TResult>The function delegate that initializes an object implementing the IDisposable interface.
testerFunc<TResult, T1, T2, T3, CancellationToken, Task<TResult>>The function delegate that is used to ensure that operations performed on
TResultabides CA2000.arg1T1The first parameter of the function delegate
testerand delegatecatcher.arg2T2The second parameter of the function delegate
testerand delegatecatcher.arg3T3The third parameter of the function delegate
testerand delegatecatcher.catcherFunc<Exception, T1, T2, T3, CancellationToken, Task>The function delegate that will handle any exceptions that might have been thrown by
tester.ctCancellationTokenThe token to monitor for cancellation requests. The default value is None.
Returns
- Task<TResult>
 A task that represents the asynchronous operation. The task result contains the return value of the function delegate
initializerif the operations succeeded; otherwise null if the operation failed.
Type Parameters
T1The type of the first parameter of the function delegate
testerand delegatecatcher.T2The type of the second parameter of the function delegate
testerand delegatecatcher.T3The type of the third parameter of the function delegate
testerand delegatecatcher.TResultThe type of the return value of the function delegate
initializer.
SafeInvokeAsync<T1, T2, T3, T4, TResult>(Func<TResult>, Func<TResult, T1, T2, T3, T4, CancellationToken, Task<TResult>>, T1, T2, T3, T4, Func<Exception, T1, T2, T3, T4, CancellationToken, Task>, CancellationToken)
Provides a generic way to abide the rule description of CA2000 (Dispose objects before losing scope).
public static Task<TResult> SafeInvokeAsync<T1, T2, T3, T4, TResult>(Func<TResult> initializer, Func<TResult, T1, T2, T3, T4, CancellationToken, Task<TResult>> tester, T1 arg1, T2 arg2, T3 arg3, T4 arg4, Func<Exception, T1, T2, T3, T4, CancellationToken, Task> catcher = null, CancellationToken ct = default) where TResult : class, IDisposable
  Parameters
initializerFunc<TResult>The function delegate that initializes an object implementing the IDisposable interface.
testerFunc<TResult, T1, T2, T3, T4, CancellationToken, Task<TResult>>The function delegate that is used to ensure that operations performed on
TResultabides CA2000.arg1T1The first parameter of the function delegate
testerand delegatecatcher.arg2T2The second parameter of the function delegate
testerand delegatecatcher.arg3T3The third parameter of the function delegate
testerand delegatecatcher.arg4T4The fourth parameter of the function delegate
testerand delegatecatcher.catcherFunc<Exception, T1, T2, T3, T4, CancellationToken, Task>The function delegate that will handle any exceptions that might have been thrown by
tester.ctCancellationTokenThe token to monitor for cancellation requests. The default value is None.
Returns
- Task<TResult>
 A task that represents the asynchronous operation. The task result contains the return value of the function delegate
initializerif the operations succeeded; otherwise null if the operation failed.
Type Parameters
T1The type of the first parameter of the function delegate
testerand delegatecatcher.T2The type of the second parameter of the function delegate
testerand delegatecatcher.T3The type of the third parameter of the function delegate
testerand delegatecatcher.T4The type of the fourth parameter of the function delegate
testerand delegatecatcher.TResultThe type of the return value of the function delegate
initializer.
SafeInvokeAsync<T1, T2, T3, T4, T5, TResult>(Func<TResult>, Func<TResult, T1, T2, T3, T4, T5, CancellationToken, Task<TResult>>, T1, T2, T3, T4, T5, Func<Exception, T1, T2, T3, T4, T5, CancellationToken, Task>, CancellationToken)
Provides a generic way to abide the rule description of CA2000 (Dispose objects before losing scope).
public static Task<TResult> SafeInvokeAsync<T1, T2, T3, T4, T5, TResult>(Func<TResult> initializer, Func<TResult, T1, T2, T3, T4, T5, CancellationToken, Task<TResult>> tester, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, Func<Exception, T1, T2, T3, T4, T5, CancellationToken, Task> catcher = null, CancellationToken ct = default) where TResult : class, IDisposable
  Parameters
initializerFunc<TResult>The function delegate that initializes an object implementing the IDisposable interface.
testerFunc<TResult, T1, T2, T3, T4, T5, CancellationToken, Task<TResult>>The function delegate that is used to ensure that operations performed on
TResultabides CA2000.arg1T1The first parameter of the function delegate
testerand delegatecatcher.arg2T2The second parameter of the function delegate
testerand delegatecatcher.arg3T3The third parameter of the function delegate
testerand delegatecatcher.arg4T4The fourth parameter of the function delegate
testerand delegatecatcher.arg5T5The fifth parameter of the function delegate
testerand delegatecatcher.catcherFunc<Exception, T1, T2, T3, T4, T5, CancellationToken, Task>The function delegate that will handle any exceptions that might have been thrown by
tester.ctCancellationTokenThe token to monitor for cancellation requests. The default value is None.
Returns
- Task<TResult>
 A task that represents the asynchronous operation. The task result contains the return value of the function delegate
initializerif the operations succeeded; otherwise null if the operation failed.
Type Parameters
T1The type of the first parameter of the function delegate
testerand delegatecatcher.T2The type of the second parameter of the function delegate
testerand delegatecatcher.T3The type of the third parameter of the function delegate
testerand delegatecatcher.T4The type of the fourth parameter of the function delegate
testerand delegatecatcher.T5The type of the fifth parameter of the function delegate
testerand delegatecatcher.TResultThe type of the return value of the function delegate
initializer.