c#~ Asynchronous Programming ~await and Async-induced w3wp.exe crashes

Source: Internet
Author: User

Strange things have happened again recently, IIS application pool did not hang out, all point to the same spear, Async,threadpool,task, There is also a system.nullreferenceexception, so these all make us feel that our async program is having problems, and the fact is that our asynchronous invocation references a non-null reference to the "context" and eventually causes the w3wp process to die!
Through other senior share, found the cause of the problem, the uncle also summed up
1 The Async method needs to wait for its result with await, which guarantees that your SynchronizationContext context is not empty, that is, there is no error with a non-null reference.

2 when calling the Async method, you can also use its configureawait (false) method if no method is added to the await keyword,although it does not save the SynchronizationContext context. However, it does not report a non-null reference error.

3 Call Async Async method in a new thread, we need to pay attention to the above two points

See article

Http://www.cnblogs.com/cmt/p/configure_await_false.html

Http://www.cnblogs.com/cmt/p/sokcet_memory_leak.html

Technical point Description

1 Task.run (() =>{}); Add a task to the thread pool, queue up for execution

2 Async identifies a method as an async method that can be executed in parallel with the main thread, exerting the multi-core advantage of the CPU

3 await you can add this modifier before calling an async method, which means to wait for the current async method to execute and then execute the following code

4 Configureawait (True), when the code is executed by synchronous execution into asynchronous execution, the current thread context information is captured and saved to SynchronizationContext for use in asynchronous execution, and is used in synchronous execution after completion of asynchronous execution

5 configurewait (flase), without capturing the thread context information, the Async method cannot get the context information of the thread before the await when it executes with the code after await. The most direct effect in ASP. Httpconext.current is null, but there is no non-null reference error

The above is what we learned in solving the w3wp.exe crashes caused by asynchrony!

Thank you for reading!

c#~ Asynchronous Programming ~await and Async-induced w3wp.exe crashes

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.