'System.Threading.Tasks.Task' does not contain a definition for 'WhenAny'_

Answered 'System.Threading.Tasks.Task' does not contain a definition for 'WhenAny'_

  • Tuesday, March 06, 2012 9:04 AM
     
      Has Code

    Hi All,

    I have copied the below code from the document "The Task-based Asynchronous Pattern"

    var recommendations = new List<Task<bool>>() 
    { 
        GetBuyRecommendation1Async(symbol), 
        GetBuyRecommendation2Async(symbol),
        GetBuyRecommendation3Async(symbol)
    };
    Task<bool> recommendation = await Task.WhenAny(recommendations);
    if (await recommendation) BuyStock(symbol);
    

    And when I compiled, I get the above mentioned error. What would have went wrong?

    Thanks for reading


    Every thing is perfect as long as you share

All Replies

  • Tuesday, March 06, 2012 9:47 AM
    Owner
     
     Answered
    What version of .NET 4 are you using?  WhenAny was added to Task in .NET 4.5.  If instead you're using .NET 4 with the Async CTP, you need to use TaskEx.WhenAny rather than Task.WhenAny.
  • Wednesday, March 07, 2012 4:38 AM
     
     

    Stephen,

    Thanks for the reply. As a matter of fact, I'm using framework 4.0, thus, the issue. But the document written by you, doesn't specify about this. Please add this.

    FYI, in the mentioned document, you have made it clear about Task.Delay is added to framework 4.5. Hence, it would be great if you modify the same document with all the new things added to framework 4.5 when compared to 4.0.

    Regards


    Every thing is perfect as long as you share


    • Edited by Chakravarthy Wednesday, March 07, 2012 4:39 AM
    •