public static CancellationToken GetCancellationToken <TCmdlet>( [NotNull] this TCmdlet cmdlet) where TCmdlet : Cmdlet, IAsyncCmdlet { var context = AsyncCmdletContext.GetContext(cmdlet); return(context.CancellationToken); }
public static void DoDispose <TCmdlet>( [NotNull] this TCmdlet cmdlet) where TCmdlet : Cmdlet, IAsyncCmdlet { var context = AsyncCmdletContext.GetContext(cmdlet); context.Dispose(); }
public AsyncCmdletScope( [NotNull] AsyncCmdletContext context) { this._context = context; this.CancellationToken = context.CancellationToken; this._oldSynchronizationContext = SynchronizationContext.Current; var syncCtx = new QueueingSynchronizationContext(this); SynchronizationContext.SetSynchronizationContext(syncCtx); }
private static Task PostAsyncOperation <TCmdlet>( [NotNull] TCmdlet cmdlet, [NotNull] Action action, bool executeSynchronously, CancellationToken cancellationToken) where TCmdlet : Cmdlet, IAsyncCmdlet { var context = AsyncCmdletContext.GetContext(cmdlet); var task = context.QueueAsyncOperation(action, executeSynchronously, cancellationToken); return(task); }
public static void DoEndProcessingAsync <TCmdlet>( [NotNull] this TCmdlet cmdlet) where TCmdlet : Cmdlet, IAsyncCmdlet { if (cmdlet is null) { throw new ArgumentNullException(nameof(cmdlet)); } var context = AsyncCmdletContext.GetContext(cmdlet); context.DoEndProcessingAsync(); }
public static void DoStopProcessing <TCmdlet>( [NotNull] this TCmdlet cmdlet) where TCmdlet : Cmdlet, IAsyncCmdlet { if (cmdlet is null) { throw new ArgumentNullException(nameof(cmdlet)); } try { var context = AsyncCmdletContext.GetContext(cmdlet); context.Cancel(); } catch (ObjectDisposedException) { } }