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


C# CancellationToken.Cancel方法代码示例

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


在下文中一共展示了CancellationToken.Cancel方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: TerminateConnection

 /// <summary>
 /// Processes the termination of client.
 /// </summary>
 private void TerminateConnection(CancellationToken cancellationToken)
 {
     try
     {
         // Cancel all asynchronous loops associated with the cancellation token and notify user
         // of terminated connection if the connection had not previously been terminated
         if (!cancellationToken.Cancel())
             OnConnectionTerminated();
     }
     catch (ThreadAbortException)
     {
         // This is a normal exception
         throw;
     }
     catch
     {
         // Other exceptions can happen (e.g., NullReferenceException) if thread
         // resumes and the class is disposed middle way through this method
     }
 }
开发者ID:GridProtectionAlliance,项目名称:gsf,代码行数:23,代码来源:TcpClient.cs

示例2: LogicalThreadOperation

        /// <summary>
        /// Creates a new instance of the <see cref="LogicalThreadOperation"/> class.
        /// </summary>
        /// <param name="thread">The thread on which to execute the operation's action.</param>
        /// <param name="action">The action to be executed.</param>
        /// <param name="priority">The priority with which the action should be executed on the logical thread.</param>
        /// <param name="autoRunIfPending">
        /// Set to <c>true</c> to execute <see cref="RunIfPending"/> automatically; otherwise, 
        /// set to <c>false</c> for user controlled call timing.
        /// </param>
        /// <exception cref="ArgumentException"><paramref name="priority"/> is outside the range between 1 and <see cref="LogicalThread.PriorityLevels"/>.</exception>
        public LogicalThreadOperation(LogicalThread thread, Action action, int priority, bool autoRunIfPending = true)
        {
            m_thread = thread;
            m_action = action;
            Priority = priority;
            m_autoRunIfPending = autoRunIfPending;

            // Initialize this class with a cancelled token so that
            // calls to EnsurePriority before the first call to
            // ExecuteActionAsync do not inadvertently queue actions
            m_cancellationToken = new CancellationToken();
            m_cancellationToken.Cancel();
        }
开发者ID:rmc00,项目名称:gsf,代码行数:24,代码来源:LogicalThreadOperation.cs


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