Asynchronously wait for Task to complete with timeout

后端 未结 16 2005
天命终不由人
天命终不由人 2020-11-21 17:49

I want to wait for a Task to complete with some special rules: If it hasn\'t completed after X milliseconds, I want to display a message to the user. And

16条回答
  •  温柔的废话
    2020-11-21 18:31

    Definitely don't do this, but it is an option if ... I can't think of a valid reason.

    ((CancellationTokenSource)cancellationToken.GetType().GetField("m_source",
        System.Reflection.BindingFlags.NonPublic |
        System.Reflection.BindingFlags.Instance
    ).GetValue(cancellationToken)).Cancel();
    

提交回复
热议问题