Quantcast
Viewing latest article 2
Browse Latest Browse All 19

async / await / task

The key word "await" has NOTHING TO DO directly with "ManualResetEvent" and "AutoResetEvent". It's ONLY a symbol to tell the compiler that the Task instance should be working in the async mode. 

Now a typical example is that:

public Task<int> SlowWork()
{
   return Task.Run(()=>{……});
}

public async Task CallSlowTask()
{
   // 1. Call the async code, let it run for a while in another thread (Task) in the async mode. The work is usually very slow
  var runningTask = SlowWork();

  // 2. Here we can run the sync code, it will block the UI or main thread, so please make them as simple and fast as possible.
  ……

 // 3. After this, when we wanna get the result from SlowWork(), we can use await to force that we want to fetch the result. Because "SlowWork()" has been running for a while, maybe the result comes in. But if the result doesn't come in yet, it wil wait in the async mode (NOT blocking the current main thread)
  var result = await runningTask;
}


Reproduce your quesions with ScreenToGif is your choice. 
For IIS: IIS Forum
For WebSite of .NET: ASP.NET Forum
For others: StackExchange
For spam-sender or forum urgent issues, Send your Email at:  forumsfeedback@microsoft.com


Viewing latest article 2
Browse Latest Browse All 19

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>