| Start |
|---|
| ASP.NET Configure Await When ASP.NET handles a request, a thread is assigned from the thread pool and a request context is created. The request context contains information about the current request which can be accessed through the static A given request context may only be active on one thread at a time. When execution reaches When the task completes the thread pool assigns another thread to continue execution of the request. The request context is then assigned to this thread. This may or may not be the original thread. BlockingWhen the result of an This is because, by default the awaited task, in this case When the entire call stack is asynchronous there is no problem because, once When we block synchronously using Therefore the deadlock arises because while the blocking thread with the request context is waiting for the asynchronous operation to complete, the asynchronous operation is trying to obtain the request context in order to complete. ConfigureAwaitBy default calls to an awaited task will capture the current context and attempt to resume execution on the context once complete. By using This can avoid deadlocks when it is necessary to block on asynchronous code, however this comes at the cost of losing the context in the continuation (code after the call to await). In ASP.NET this means that if your code following a call to If For this reason it is often recommended to use |
| Async/await See below for a simple example of how to use async/await to do some time intensive stuff in a background process while maintaining the option of doing some other stuff that do not need to wait on the time intensive stuff to complete. However, if you need to work with the result of the time intensive method later, you can do this by awaiting the execution. |
| BackgroundWorker See below for a simple example of how to use a You need to:
In addition to the
|
| Task See below for a simple example of how to use a All you need to do is wrap your time intensive method in a |
| Thread See below for a simple example of how to use a As you can see we can not return a value from our To get a return value from a |
| Task "run and forget" extension In certain cases (e.g. logging) it might be useful to run task and do not await for the result. The following extension allows to run task and continue execution of the rest code: The result is awaited only inside the extension method. Since An example how to use the extension: RemarksTo run any of these examples just call them like that: |
Read Article
https://develop.horje.com/learn/1434/reference