我已經創建了一個通過使用如下所示的交換服務器來讀取收件箱中新郵件的方法。如何將這些IEnumerable集合添加到隊列中並異步處理隊列中的每個列表項?如何將IEumerable集合添加到隊列並在.NET中異步處理每個項目?
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);
}
我想處理隊列中的每個項目asynchronosly – JEMI
比你需要改善你的問題。你的算法的哪些步驟必須異步執行? – Lazin
我已經通過添加我需要異步執行的方法更新了問題 – JEMI