Asynchronously wait for Task to complete with timeout

后端 未结 16 2024
天命终不由人
天命终不由人 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:40

    If you use a BlockingCollection to schedule the task, the producer can run the potentially long running task and the consumer can use the TryTake method which has timeout and cancellation token built in.

提交回复
热议问题