Set TaskCompletionSource.Task status as running

485 views Asked by At

I have an external long running process (web API call) which I have to track in order to know when it completes. I'd like to encapsulate it in a task. TaskCompletionSource seems to be the right tool to achieve that. But the task associated to TaskCompletionSource has never the running status. It starts with the WaitingForActivation status and get the RanToCompletion status once the result has been set. In order to include this inside a more general frame, I need to know that the underlying long process is running. In this case, the task should have the Running status. I'm wondering how I can get/force/simulate this behavior.

And above this practical question, I don't understand the design choice of bypassing the "running" status with TaskCompletionSource. We could have been allowed to use the Start method to set the status to "Running". It seems simple and straighforward. But calling "Start" throw an exception. I don't understand this choice.

Hope it's clear. Thanks in advance.

0

There are 0 answers