作者热门文章
- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
我已经创建了一个方法来使用交换服务器读取收件箱新消息,如下所示。如何将这些 IEnumerable 集合添加到队列并异步处理队列中的每个项目列表?
private static IEnumerable<ExchangeEmailInformation> GetInboxItems(ExchangeService service)
{
var emailInformations = new List<ExchangeEmailInformation>();
try
{
SearchFilter searchFilter = new SearchFilter.SearchFilterCollection(LogicalOperator.And, new SearchFilter.IsEqualTo(EmailMessageSchema.IsRead, false));
var itemview = new ItemView(int.MaxValue);
FindItemsResults<Item> findResults = service.FindItems(WellKnownFolderName.Inbox, searchFilter, itemview);
Console.WriteLine("\n-------------Result found:-------------");
service.LoadPropertiesForItems(findResults, PropertySet.FirstClassProperties);
foreach (var item in findResults)
{
emailInformations.Add(new ExchangeEmailInformation
{
Attachment = item.Attachments ?? null,
Body = item.Body.BodyType == BodyType.HTML ? ConvertHtml.ToText(item.Body.Text) : item.Body.Text,
Subject = item.Subject,
RecievedDate = item.DateTimeReceived
});
}
}
catch (Exception ee)
{
Console.WriteLine("\n-------------Error occured:-------------");
Console.WriteLine(ee.Message.ToString());
Console.WriteLine(ee.InnerException.ToString());
Console.ReadKey();
}
return emailInformations;
}
以下是我需要使用队列中的每个项目异步调用的过程
static void AddAttachment(string subject ,string docId, string user, string fileName)
{
var url = new StringBuilder();
url.Append(string.Format("https://webdemo-t.test.com:8443/Services/Service/MyService.svc/AddAttachment?User={0}&Engagement={1}&FileName={2}&DocumentTrasferID={3}", user, subject, fileName, docId));
Console.WriteLine(url.ToString());
WebRequest request = WebRequest.Create(url.ToString());
var credential = new NetworkCredential("user", "xxxx", "xxxx");
request.Credentials = credential;
WebResponse ws = request.GetResponse();
Encoding enc = System.Text.Encoding.GetEncoding(1252);
var responseStream = new StreamReader(ws.GetResponseStream());
string response = responseStream.ReadToEnd();
responseStream.Close();
Console.WriteLine(response);
}
最佳答案
如果您的 .NET 是 4.0 或 smth,您是否尝试过 AsParallel
扩展方法?
关于c# - 如何将 IEumerable 集合添加到队列并在 .NET 中异步处理每个项目?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13947224/
我已经创建了一个方法来使用交换服务器读取收件箱新消息,如下所示。如何将这些 IEnumerable 集合添加到队列并异步处理队列中的每个项目列表? private static IEnumerable
我是一名优秀的程序员,十分优秀!