简体   繁体   中英

ThreadPool.QueueUserWorkItem with Async Call within the thread

I have a MonoTouch application that use a ThreadPool to manage the number of background threads. If I have the ThreadPool spawn off a thread and within the thread, it fires an Async web request, will the web request spawn off a 2nd thread? if so, will that thread be taken off of the ThreadPool?

What is the best practice for such a thing? Should the web request just be a synchronous call, to lower the current thread count?

ThreadPool.QueueUserWorkItem(callback =>
{
    WebClient client = new WebClient();
    client.DownloadStringAsync(new Uri("http://www.google.com/"));
    client.DownloadStringCompleted += (a,b) => Console.WriteLine("Done");
});

If you´re ending your threadpool callback right afterwards, like you´ve shown there, there shouldn`t be a problem. You´re just replacing one threadpool call timeline with another.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM