C#foreach:将请求发送到服务器并获得响应 [英] c# foreach: send request to server and get response
问题描述
我如何在foreach中将请求发送到服务器以及何时获得响应-做一些我得到的信息.完成信息处理后,继续进行每个操作.
我的问题:在foreach中,我发送了很多请求,并且foreach继续进行处理,并得到了我作为回应的信息.
例如:
foreach(listBoxFetInfo.Items中的DataLoader.GetInfo项目){DownloadInfo(items.CompanyName);}
和
void DownloadInfo(字符串名称){//发送请求}
和
feed.RequestCompanyName + =新的IFeedEvents_RequestCompanyNameEventHandler(feed_RequestName);
和
void feed_RequestName{//获取信息并保存到文件}
此方法有不同的解决方案,但是其中之一是使用多个异步任务,并尝试在单独的任务中下载每个URL,并在下载文件后成功处理结果.有关更多信息,请参见以下链接:
How i can send request to server in foreach and when i get response - do something whith information which i get. When information process is done, continue foreach.
My problem: in foreach i send much request and foreach continue whithout process with information which i get in response.
For example:
foreach (DataLoader.GetInfo items in listBoxFetInfo.Items)
{
DownloadInfo(items.CompanyName);
}
and
void DownloadInfo(string name)
{
//Send request
}
and
feed.RequestCompanyName += new IFeedEvents_RequestCompanyNameEventHandler(feed_RequestName);
and
void feed_RequestName
{
//get information and save to file
}
There are different solution for this approach, but one of them is using Multiple Async Tasks and try to download each url in separate Task and after downloading the file successfully handle the result. For more information you can see this link:
Start Multiple Async Tasks and Process Them As They Complete
这篇关于C#foreach:将请求发送到服务器并获得响应的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!