当前位置: 首页>>代码示例>>C#>>正文


C# Threading.CancellationTokenRegistration类代码示例

本文整理汇总了C#中System.Threading.CancellationTokenRegistration的典型用法代码示例。如果您正苦于以下问题:C# CancellationTokenRegistration类的具体用法?C# CancellationTokenRegistration怎么用?C# CancellationTokenRegistration使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


CancellationTokenRegistration类属于System.Threading命名空间,在下文中一共展示了CancellationTokenRegistration类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: DefaultCancellationTokenRegistration

        public void DefaultCancellationTokenRegistration()
        {
            var registration = new CancellationTokenRegistration ();

            // shouldn't throw
            registration.Dispose ();
        }
开发者ID:mesheets,项目名称:Theraot-CF,代码行数:7,代码来源:CancellationTokenTests.cs

示例2: SaveChanges

        /// <summary>
        /// If AutoSaveChanges is set this method will auto commit changes
        /// </summary>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        protected virtual Task<int> SaveChanges(CancellationToken cancellationToken)
        {
            var source = new TaskCompletionSource<int>();
            if (AutoSaveChanges) {
                var registration = new CancellationTokenRegistration();
                if (cancellationToken.CanBeCanceled) {
                    if (cancellationToken.IsCancellationRequested) {
                        source.SetCanceled();
                        return source.Task;
                    }
                    registration = cancellationToken.Register(CancelIgnoreFailure);
                }

                try
                {
                    return _uow.SaveChangesAsync(cancellationToken);
                }
                catch (Exception e)
                {
                    source.SetException(e);
                }
                finally
                {
                    registration.Dispose();
                }
            }
            return source.Task;
        }
开发者ID:rubenknuijver,项目名称:Jigsaw,代码行数:33,代码来源:DataStore.cs

示例3: TypePropertiesForCancellationTokenRegistrationAreCorrect

        public void TypePropertiesForCancellationTokenRegistrationAreCorrect()
        {
            Assert.AreEqual(typeof(CancellationTokenRegistration).GetClassName(), "Bridge.CancellationTokenRegistration", "FullName");

            object ctr = new CancellationTokenRegistration();
            Assert.True(ctr is CancellationTokenRegistration, "CancellationTokenRegistration");
            Assert.True(ctr is IDisposable, "IDisposable");
            Assert.True(ctr is IEquatable<CancellationTokenRegistration>, "IEquatable<CancellationTokenRegistration>");
        }
开发者ID:TinkerWorX,项目名称:Bridge,代码行数:9,代码来源:CancellationTokenTests.cs

示例4: FromAsync

        // Similar to TaskFactory.FromAsync, except it supports cancellation using ICancellableAsyncResult.
        public static Task FromAsync(Func<AsyncCallback, object, ICancellableAsyncResult> beginMethod,
            Action<IAsyncResult> endMethod, CancellationToken cancellationToken)
        {
            TaskCompletionSource<object> source = new TaskCompletionSource<object>();

            CancellationTokenRegistration cancellationRegistration = new CancellationTokenRegistration();
            bool cancellationRegistrationDisposed = false;
            object cancellationRegistrationLock = new object();

            ICancellableAsyncResult result = beginMethod.Invoke((ar) =>
            {
                lock (cancellationRegistrationLock)
                {
                    cancellationRegistration.Dispose();
                    cancellationRegistrationDisposed = true;
                }

                try
                {
                    endMethod.Invoke(ar);
                    source.SetResult(null);
                }
                catch (OperationCanceledException)
                {
                    source.SetCanceled();
                }
                catch (Exception exception)
                {
                    source.SetException(exception);
                }
            }, null);

            lock (cancellationRegistrationLock)
            {
                if (!cancellationRegistrationDisposed)
                {
                    cancellationRegistration = cancellationToken.Register(result.Cancel);
                }
            }

            if (result.CompletedSynchronously)
            {
                System.Diagnostics.Debug.Assert(source.Task.IsCompleted);
            }

            return source.Task;
        }
开发者ID:rafaelmtz,项目名称:azure-webjobs-sdk,代码行数:48,代码来源:CancellableTaskFactory.cs

示例5: RSessionRequestSource

        public RSessionRequestSource(bool isVisible, CancellationToken ct) {
            _createRequestTcs = new TaskCompletionSourceEx<IRSessionInteraction>();
            _responseTcs = new TaskCompletionSourceEx<object>();
            _cancellationTokenRegistration = ct.Register(() => _createRequestTcs.TrySetCanceled(cancellationToken:ct));

            IsVisible = isVisible;
        }
开发者ID:Microsoft,项目名称:RTVS,代码行数:7,代码来源:RSessionRequestSource.cs

示例6: ScheduledAsyncTask

 protected ScheduledAsyncTask(AbstractScheduledEventExecutor executor, PreciseDeadline deadline,
     TaskCompletionSource promise, CancellationToken cancellationToken)
     : base(executor, deadline, promise)
 {
     _cancellationToken = cancellationToken;
     _cancellationTokenRegistration = cancellationToken.Register(CancellationAction, this);
 }
开发者ID:helios-io,项目名称:helios,代码行数:7,代码来源:ScheduledAsyncTask.cs

示例7: IrcNetworkStream

        internal IrcNetworkStream(IIrcClient client)
        {   
            _streamReader = new StreamReader(client.GetClientStream());
            _streamWriter = new StreamWriter(client.GetClientStream());

            _cancellationRegistration = _cancellationToken.Register(TaskRequestErrorCallback);
        }
开发者ID:Lepstr,项目名称:TmiDotNet,代码行数:7,代码来源:IrcNetworkStream.cs

示例8: StartAsyncCore

 private async Task StartAsyncCore(CancellationToken cancellationToken)
 {
     ListenerFactoryContext context = new ListenerFactoryContext(cancellationToken);
     _listener = await _factory.CreateAsync(context);
     _cancellationRegistration = _cancellationSource.Token.Register(_listener.Cancel);
     await _listener.StartAsync(cancellationToken);
 }
开发者ID:Bjakes1950,项目名称:azure-webjobs-sdk,代码行数:7,代码来源:ListenerFactoryListener.cs

示例9: Http2ClientStream

 public Http2ClientStream(int id, Priority priority, WriteQueue writeQueue, HeaderWriter headerWriter, CancellationToken cancel)
     : base(id, writeQueue, headerWriter, cancel)
 {
     _priority = priority;
     _responseTask = new TaskCompletionSource<IList<KeyValuePair<string, string>>>();
     _outputStream = new OutputStream(id, _priority, writeQueue);
     _cancellation = _cancel.Register(Cancel, this);
 }
开发者ID:Tratcher,项目名称:HTTP-SPEED-PLUS-MOBILITY,代码行数:8,代码来源:Http2ClientStream.cs

示例10: SchedulerOperationAwaiter

        internal SchedulerOperationAwaiter(Func<Action, IDisposable> schedule, CancellationToken cancellationToken, bool postBackToOriginalContext)
        {
            _schedule = schedule;
            _cancellationToken = cancellationToken;
            _postBackToOriginalContext = postBackToOriginalContext;

            _ctr = _cancellationToken.Register(Cancel);
        }
开发者ID:jamilgeor,项目名称:rx,代码行数:8,代码来源:SchedulerOperation.cs

示例11: ClientSelectionDialog

        internal ClientSelectionDialog(MetroWindow parentWindow)
            : base(parentWindow, null)
        {
            InitializeComponent();

            this.ctlList.ItemsSource = SongInfo.LastResult;

            this.m_tcs = new TaskCompletionSource<object>();
            this.m_cancel = DialogSettings.CancellationToken.Register(() => this.m_tcs.TrySetResult(null));
        }
开发者ID:Usagination,项目名称:Decchi,代码行数:10,代码来源:ClientSelectionDialog.xaml.cs

示例12: VerifierDialog

        internal VerifierDialog(MainWindow parentWindow)
            : base(parentWindow, null)
        {
            InitializeComponent();

            this.m_mainwindow = parentWindow;

            this.m_tcs = new TaskCompletionSource<object>();
            this.m_cancel = DialogSettings.CancellationToken.Register(() => this.m_tcs.TrySetResult(null));
        }
开发者ID:Usagination,项目名称:Decchi,代码行数:10,代码来源:VerifierDialog.xaml.cs

示例13: RunAsync

		public Task RunAsync(IEnumerable<ITest> selectedTests, IProgress<double> progress, TextWriter output, CancellationToken cancellationToken)
		{
			this.progress = progress;
			this.output = output;
			progressPerTest = 1.0 / GetExpectedNumberOfTestResults(selectedTests);
			tcs = new TaskCompletionSource<object>();
			Start(selectedTests);
			cancellationTokenRegistration = cancellationToken.Register(Cancel, true);
			return tcs.Task;
		}
开发者ID:2594636985,项目名称:SharpDevelop,代码行数:10,代码来源:TestRunnerBase.cs

示例14: ADSelectionDialog

        internal ADSelectionDialog(MetroWindow parentWindow)
            : base(parentWindow, null)
        {
            InitializeComponent();

            this.ctlList.ItemsSource = IParseRule.RulesPlayer;

            this.m_tcs = new TaskCompletionSource<object>();
            this.m_cancel = DialogSettings.CancellationToken.Register(() => this.m_tcs.TrySetResult(null));
        }
开发者ID:Usagination,项目名称:Decchi,代码行数:10,代码来源:ADSelectionDialog.xaml.cs

示例15: StopSignal

        public StopSignal()
        {
            _stopRequested = new TaskCompletionSource<bool>();

            _stopToken = new CancellationTokenSource();
            _registration = _stopToken.Token.Register(() =>
            {
                _stopRequested.TrySetResult(true);

                _registration.Dispose();
            });
        }
开发者ID:kotvisbj,项目名称:MassTransit,代码行数:12,代码来源:StopSignal.cs


注:本文中的System.Threading.CancellationTokenRegistration类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。