添加链接
link之家
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接
Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

I have a complicate problem.

I am using .net 4.0 MVC 4, add References about Microsoft BLC for using async, await.

and wrote

await System.Threading.Tasks.TaskEx.WhenAll(tl);

for wait Threads work ends of course. But error pops out here.

Error   13  The type or namespace name 'TaskEx' does not exist in the namespace 'System.Threading.Tasks' (are you missing an assembly reference?)   

I tested many times another Project on another Solution, but it's work. not like this.

Any ideas for little help?

whole Method here.

public async void SendEmailEwsAsync(string subject, string mailBody, string fileName)
            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("[email protected]"))); 
            mail.SendAndSaveCopy(new FolderId(WellKnownFolderName.SentItems, new Mailbox("[email protected]"))); 
        System.Threading.Tasks.Task task = new System.Threading.Tasks.Task(action);
        task.Start();
        return task;

whole References here

Project References List

Thank you for see this.

If you mean ASP.NET MVC, you can't use Microsoft.Bcl.Async on ASP.NET. Even if you get it to compile (which is possible), it will not behave properly at runtime. – Stephen Cleary Mar 15, 2016 at 15:25 @StephenCleary for real? Actually, I did add References about MVC in this project, but it's A kind of common library in my another MVC project. so I remove MVC reference, but still doesn't work. – cleanUser_999 Mar 16, 2016 at 3:04 To be clear, Microsoft.Bcl.Async cannot be used on ASP.NET at all. To use async on ASP.NET, you have to upgrade to at least .NET 4.5. – Stephen Cleary Mar 16, 2016 at 11:23

You do not need to reference TaskEx, and you can do WaitAll instead of WhenAll

// Wait for all tasks in list to complete
Task.WaitAll(tl);
                Thx for your comment! one question, is that exactly same work? between TaskEx.WhenAll() and Task.WaitAll() ?
– cleanUser_999
                Mar 15, 2016 at 6:39
                The WhenAll() method will actually create a new, awaitable task that you can await, while the WaitAll() doesen't. Fine grained difference there, and all depends of course of what you want to. There is a good answer here: stackoverflow.com/questions/6123406/waitall-vs-whenall
– Pedro G. Dias
                Mar 15, 2016 at 6:45
                I already have Syncronous method. so I want make Asyncronous one. Seem like WaitAll() is Block type right? but still I thanks for your attention.
– cleanUser_999
                Mar 15, 2016 at 6:51
        

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question. Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.