Task.Yield Method RRS feed

  • Question

  • I checked the description of the document:
    Creates an awaitable task that asynchronously yields back to the current context when awaited.

    Does it mean that await task.Yield is equivalent to this.begininvoke in winform program.

    I saw people saying that
    1.Task.Yield has a notification thread to do other things
    2.Task.Yield gives up the function of the current thread
    Are these two statements wrong?
    I think
    The role of await Task.Yield is equivalent to BeginInvoke in winform

    please verify my account

    Thursday, October 25, 2018 7:56 AM


  • Please read the following:

    When you use async/await, there is no guarantee that the method you call when you do await FooAsync() will actually run asynchronously. The internal implementation is free to return using a completely synchronous path.

    If you're making an API where it's critical that you don't block and you run some code asynchronously, and there's a chance that the called method will run synchronously (effectively blocking), using await Task.Yield() will force your method to be asynchronous, and return control at that point. The rest of the code will execute at a later time (at which point, it still may run synchronously) on the current context.

    it's taken from the following post that explains the use of Task.Yield :

    and also the following post also explains very well about it:

    Hope that helps!

    [If a post helps to resolve your issue, please click the "Mark as Answer" of that post or click Answered "Vote as helpful" button of that post. By marking a post as Answered or Helpful, you help others find the answer faster. ]

    Blog | LinkedIn | Stack Overflow | Facebook
    profile for Ehsan Sajjad on Stack Exchange, a network of free, community-driven Q&A sites

    Thursday, October 25, 2018 2:11 PM