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
Post a Comment