简体   繁体   English

ThreadPool.QueueUserWorkItem与线程内的异步调用

[英]ThreadPool.QueueUserWorkItem with Async Call within the thread

I have a MonoTouch application that use a ThreadPool to manage the number of background threads. 我有一个MonoTouch应用程序,它使用ThreadPool来管理后台线程的数量。 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? 如果我让ThreadPool从一个线程产生并在线程内,它会触发一个异步Web请求,Web请求会产生第二个线程吗? if so, will that thread be taken off of the ThreadPool? 如果是这样,该线程将从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? Web请求是否应该是同步调用,以降低当前的线程数?

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. 你只是用另一个替换一个线程池调用时间线。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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