c#~ Asynchronous Programming Continue ~ You have to know the throw in the ThreadPool

Source: Internet
Author: User

The problem still exists.

Previously written related articles asynchronous programming articles, this article is mainly a little supplement, before the IIS often send w3wp process no hanging, but has not been able to find the real reason, and find relevant information, find some related articles, such as await and async caused by thread deadlock , have also been analyzed, but the situation with our project is somewhat different, because in our project only use ThreadPool and task.run this thread pool, and asynchronous use is also asynchronous to the end !

Today inadvertently saw an article, said in the ThreadPool if there is an exception, and you do not capture it, directly throw, this will also refer to the death of the w3wp process, I tried on the computer, there is such a situation, so very excited!

In the Event Viewer,

Finally, my thread pool method has been improved to solve this problem.

Optimized code

   /// <summary>    ///Thread Management/// </summary>     Public classThreadmanager {/// <summary>        ///queue The specified work running on the thread pool/// </summary>        /// <param name= "action" ></param>         Public Static voidRun (Action action) {ThreadPool.QueueUserWorkItem (U=            {                Try{action (); }                Catch(Exception ex) {Lind.DDD.Logger.LoggerFactory.Instance.Logger_Error (ex);        }            }); }    }

Finally, it is very happy to find another cause of the w3wp process hanging off, I hope this time can really solve this problem!

c#~ Asynchronous Programming Continue ~ You have to know the throw in the ThreadPool

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.