• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C# Threading.CancellationTokenRegistration类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

        protected TransferControllerBase(TransferScheduler transferScheduler, TransferJob transferJob, CancellationToken userCancellationToken)
        {
            if (null == transferScheduler)
            {
                throw new ArgumentNullException("transferScheduler");
            }

            if (null == transferJob)
            {
                throw new ArgumentNullException("transferJob");
            }

            this.Scheduler = transferScheduler;
            this.TransferJob = transferJob;

            this.transferSchedulerCancellationTokenRegistration =
                this.Scheduler.CancellationTokenSource.Token.Register(this.CancelWork);

            this.userCancellationTokenRegistration = userCancellationToken.Register(this.CancelWork);
            this.TaskCompletionSource = new TaskCompletionSource<object>();
        }
开发者ID:BeauGesteMark,项目名称:azure-storage-net-data-movement,代码行数:21,代码来源:TransferControllerBase.cs


示例6: Delay

        public static Task Delay(int dueTimeMs, CancellationToken cancellationToken)
        {
            if (dueTimeMs < -1) throw new ArgumentOutOfRangeException("dueTimeMs", "Invalid due time");
            if (cancellationToken.IsCancellationRequested) return preCanceledTask;
            if (dueTimeMs == 0) return preCompletedTask;

            var tcs = new TaskCompletionSource<object>();
            var ctr = new CancellationTokenRegistration();
            var timer = new Timer(self =>
            {
                ctr.Dispose();
                ((Timer) self).Dispose();
                tcs.TrySetResult(null);
            });
            if (cancellationToken.CanBeCanceled)
                ctr = cancellationToken.Register(() =>
                {
                    timer.Dispose();
                    tcs.TrySetCanceled();
                });
            timer.Change(dueTimeMs, -1);
            return tcs.Task;
        }
开发者ID:nbouilhol,项目名称:bouilhol-lib,代码行数:23,代码来源:TaskEx.cs


示例7: ExecuteScalarAsync

        public virtual Task<object> ExecuteScalarAsync(CancellationToken cancellationToken) {
            if (cancellationToken.IsCancellationRequested) {
                return ADP.CreatedTaskWithCancellation<object>();
            }
            else {
                CancellationTokenRegistration registration = new CancellationTokenRegistration();
                if (cancellationToken.CanBeCanceled) {
                    registration = cancellationToken.Register(CancelIgnoreFailure);
                }

                try {
                    return Task.FromResult<object>(ExecuteScalar());
                }
                catch (Exception e) {
                    registration.Dispose();
                    return ADP.CreatedTaskWithException<object>(e);
                }
            }
        }
开发者ID:krytht,项目名称:DotNetReferenceSource,代码行数:19,代码来源:DBCommand.cs


示例8: ExecuteDbDataReaderAsync

        protected virtual Task<DbDataReader> ExecuteDbDataReaderAsync(CommandBehavior behavior, CancellationToken cancellationToken) {
            if (cancellationToken.IsCancellationRequested) {
                return ADP.CreatedTaskWithCancellation<DbDataReader>();
            }
            else {
                CancellationTokenRegistration registration = new CancellationTokenRegistration();
                if (cancellationToken.CanBeCanceled) {
                    registration = cancellationToken.Register(CancelIgnoreFailure);
                }

                try {
                    return Task.FromResult<DbDataReader>(ExecuteReader(behavior));
                }
                catch (Exception e) {
                    registration.Dispose();
                    return ADP.CreatedTaskWithException<DbDataReader>(e);
                }
            }
        }
开发者ID:krytht,项目名称:DotNetReferenceSource,代码行数:19,代码来源:DBCommand.cs


示例9: DeactivateActiveRequest

            private void DeactivateActiveRequest(
                SafeCurlMultiHandle multiHandle, EasyRequest easy, 
                IntPtr gcHandlePtr, CancellationTokenRegistration cancellationRegistration)
            {
                // Remove the operation from the multi handle so we can shut down the multi handle cleanly
                int removeResult = Interop.libcurl.curl_multi_remove_handle(multiHandle, easy._easyHandle);
                Debug.Assert(removeResult == CURLMcode.CURLM_OK, "Failed to remove easy handle"); // ignore cleanup errors in release

                // Release the associated GCHandle so that it's not kept alive forever
                if (gcHandlePtr != IntPtr.Zero)
                {
                    try
                    {
                        GCHandle.FromIntPtr(gcHandlePtr).Free();
                        _activeOperations.Remove(gcHandlePtr);
                    }
                    catch (InvalidOperationException)
                    {
                        Debug.Fail("Couldn't get/free the GCHandle for an active operation while shutting down due to failure");
                    }
                }

                // Undo cancellation registration
                cancellationRegistration.Dispose();
            }
开发者ID:RendleLabs,项目名称:corefx,代码行数:25,代码来源:CurlHandler.MultiAgent.cs


示例10: GetTokenReg

		CancellationTokenRegistration GetTokenReg ()
		{
			CancellationTokenRegistration registration
				= new CancellationTokenRegistration (Interlocked.Increment (ref currId), this);
			
			return registration;
		}
开发者ID:rmartinho,项目名称:mono,代码行数:7,代码来源:CancellationTokenSource.cs


示例11: 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


示例12: 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


示例13: 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


示例14: 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


示例15: 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


示例16: 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


示例17: 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


示例18: 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


示例19: 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


示例20: 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



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# Threading.CancellationTokenSource类代码示例发布时间:2022-05-26
下一篇:
C# Threading.CancellationToken类代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap