none
What does Task.Wait(CancellationToken) do? RRS feed

  • Question

  • What does Task.Wait(CancellationToken) do?

    The documentation does not explain task wait using the cancellation token. Since I am using cancellation tokens, I assume I should use it in the wait. But what if I don't supply it? What's the difference?

    Monday, September 30, 2013 1:33 AM

Answers

  • "The documentation does not explain task wait using the cancellation token."

    Hmm, the documentation has an example that looks reasonable to me: http://msdn.microsoft.com/en-us/library/dd321315.aspx

    "But what if I don't supply it? What's the difference?"

    If you don't supply a cancellation token then you won't be able to cancel the wait, it will always wait until the task completes.

    • Marked as answer by DavidSherwood Monday, September 30, 2013 3:47 PM
    Monday, September 30, 2013 6:35 AM
    Moderator

All replies

  • "The documentation does not explain task wait using the cancellation token."

    Hmm, the documentation has an example that looks reasonable to me: http://msdn.microsoft.com/en-us/library/dd321315.aspx

    "But what if I don't supply it? What's the difference?"

    If you don't supply a cancellation token then you won't be able to cancel the wait, it will always wait until the task completes.

    • Marked as answer by DavidSherwood Monday, September 30, 2013 3:47 PM
    Monday, September 30, 2013 6:35 AM
    Moderator
  • Thanks for the reference. I was looking at Net 4.0 documentation.

    I looks like in my case i will not need it. My task waits on the cancellation token wait handle in addition to a event wait handle.

    Monday, September 30, 2013 3:47 PM