我是新来的。
我有一个复杂的问题。
我正在使用.net 4.0MVC4,添加有关Microsoft BLC的参考资料以使用异步,等待。
并写道
await System.Threading.Tasks.TaskEx.WhenAll(tl);当然,for wait Thread的工作结束了。但是这里会出现错误。
Error 13 The type or namespace name 'TaskEx' does not exist in the namespace 'System.Threading.Tasks' (are you missing an assembly reference?) 我在另一个解决方案上多次测试了另一个项目,但它是有效的。不是这样的。
有什么小帮助的想法吗?
这里有完整的方法。
public async void SendEmailEwsAsync(string subject, string mailBody, string fileName)
{
try
{
List<System.Threading.Tasks.Task> tl = new List<System.Threading.Tasks.Task>();
foreach (var kvp in Receivers)
{
EmailMessage mail = CreateMailEws(subject, mailBody);
mail.ToRecipients.Add(kvp.Value);
if (!this.TestFlag)
{
mail.Attachments.AddFileAttachment(string.Format(fileName, EmailNamePair[kvp.Value]), kvp.Key);
}
tl.Add(TaskSendAsync(mail));
this.CurrentCursor++;
}
await System.Threading.Tasks.TaskEx.WhenAll(tl); //error here
}
catch (Exception e)
{
throw e;
}
finally
{
this.IsEnd = true;
}
}
private System.Threading.Tasks.Task TaskSendAsync(EmailMessage mail)
{
Action action = delegate()
{
mail.Save(new FolderId(WellKnownFolderName.Drafts, new Mailbox("noreply@whatever.com")));
mail.SendAndSaveCopy(new FolderId(WellKnownFolderName.SentItems, new Mailbox("noreply@whatever.com")));
};
System.Threading.Tasks.Task task = new System.Threading.Tasks.Task(action);
task.Start();
return task;
}这里有完整的参考文献
Project References List
谢谢你看了这个。
发布于 2016-03-15 14:34:22
您不需要引用TaskEx,并且可以使用WaitAll代替WhenAll
// Wait for all tasks in list to complete
Task.WaitAll(tl);https://stackoverflow.com/questions/36004146
复制相似问题