c# - How to write simple async method? -


using latest ctp5 async/await keywords, wrote code, apparently cannot compile:

 class program     {         public class myclass         {             async public task<int> test()             {                 var result = await taskex.run(() =>                     {                         thread.sleep(3000);                         return 3;                     });                 return result;             }         }          static void main(string[] args)         {             var myclass = new myclass();              //the 'await' operator can used in method or lambda marked 'async' modifier error ??!!             int result = await myclass.test();              console.readline();         }     } 

what th reason of "the 'await' operator can used in method or lambda marked 'async' modifier error?" (i've selected line visual studio point me to)

i don't know if can mark main async, need include async keyword in declaration of method uses await. example:

public async void dostuffasync () {     var myclass = new myclass ();      int result = await myclass.testasync (); } 

Comments

Popular posts from this blog

linux - Using a Cron Job to check if my mod_wsgi / apache server is running and restart -

actionscript 3 - TweenLite does not work with object -

jQuery Ajax Render Fragments OR Whole Page -