Wait()
does not call the Start()
task. If you call Wait()
on an unallocated task, it will wait until it starts and ends until it finishes, the wait time will be stopped, or the wait will be canceled. Since your Wait()
call does not contain a cancellation token or timeout, this is infinite to complete the task.
I think that confuses you from the blog:
However, if it is not already running, Wait can be done by the task from the scheduler to which it has been queued, and it is embedded in the current thread to execute it.
The key here is the phrase "do not start execution." This does not mean that Start()
not called, but Start()
was called, which planned the task and made it ready for execution, but the task did not start.
Start()
it is necessary to schedule the task, it does not immediately start execution. This is the main thing in this commercial. If the task is ready to work, but not planned, it can be integrated. But he will not launch a task that was not even planned.
If you look at TaskStatus
on MSDN ( See here ), you will see the following values:
- Created
- Waiting for activation
- WaitingToRun
- Launch
- WaitingForChildrenToComplete
- Rantocompletion
- Canceled
- Faulted
When you create a task (with a new one or a factory), it is in the Created
state. Nothing happens to the task in this state. After its launch, it moves to WaitingForActivation
, etc., WaitingForActivation
THIS point until it reaches Running
, in accordance with this block it can be built-in.
So, a short story, creating a task, simply puts it in the Created
state and does not start it if Wait()
called. It makes sense?