C#foreach:将请求发送到服务器并获得响应 [英] c# foreach: send request to server and get response

查看:54
本文介绍了C#foreach:将请求发送到服务器并获得响应的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何在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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆