Check if task is already running before starting new

前端 未结 4 1610
旧时难觅i
旧时难觅i 2020-12-29 02:32

There is a process which is executed in a task. I do not want more than one of these to execute simultaneously.

Is this the correct way to check to see if a task is

4条回答
  •  难免孤独
    2020-12-29 03:15

    As suggested by Jon Skeet, the Task.IsCompleted is the better option.

    According to MSDN:

    IsCompleted will return true when the task is in one of the three final states: RanToCompletion, Faulted, or Canceled.

    But it appears to return true in the TaskStatus.WaitingForActivation state too.

提交回复
热议问题