ITPub博客

首页 > 应用开发 > > C# 中 CancellationTokenSource 使用问题

C# 中 CancellationTokenSource 使用问题

作者:emanda 时间:2019-09-17 11:25:11 0 删除 编辑

请问下面的代码中如果 ExecuteOperation(op) 执行超时,会发生什么情况?

IOperationResult IMemcachedNode.Execute(IOperation op)
{
    var cts = new CancellationTokenSource();
    cts.CancelAfter(timeout);
    void Cancel()
    {
        _logger.LogWarning($"Timeout to {nameof(IMemcachedNode.Execute)}({op})");
    }
    cts.Token.Register(Cancel);
    return ExecuteOperation(op);
}


来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/1741/viewspace-3133793/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2019-04-15

  • 博文量
    208
  • 访问量
    2571