Wait for an async-continuation before proceeding RRS feed

  • Question

  • I'm using async/await to provide a continuation for a task that needs to be run in the UI context. However, the continuation may be pre-empted by another block of code that needs to wait for it to finish. Using Task.Wait() will return as soon as the Task finishes but will not guarantee that the async continuation has also completed. Is there any (elegant) way to force the continuations to be run before continuing excecution? (Using semaphores etc. will obviously deadlock because the pre-empting code will just block never allowing the continuation to happen, because they both run on the same thread).


    Wednesday, July 30, 2014 12:09 PM

All replies

  • What is the continuation for a task? Post some code for better understanding.

    Thursday, July 31, 2014 5:18 AM
  • It isn't really relevant what code is in the continuation. It just cleans up the application state in case the task faults/is cancelled prematurely. I don't want to run the cleanup code any place that's waiting on the task. I'm thinking now that if Await callbacks are FIFO (first in first out) then I can just Task.Wait to wait synchronously then Await the task to force the previously scheduled continuation to run.
    Thursday, August 7, 2014 6:56 PM