示例#1
0
        public static CancellationToken GetCancellationToken <TCmdlet>(
            [NotNull] this TCmdlet cmdlet)
            where TCmdlet : Cmdlet, IAsyncCmdlet
        {
            var context = AsyncCmdletContext.GetContext(cmdlet);

            return(context.CancellationToken);
        }
示例#2
0
        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);
        }
示例#4
0
        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);
        }
示例#5
0
        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();
        }
示例#6
0
        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)
            {
            }
        }