3 ms·
Been using this in a new Win8 app I'm working on - I have to say, the await keyword and the Task<T> object make the code much cleaner
by varunsrin 15y ago
Been using this in a new Win8 app I'm working on - I have to say, the await keyword and the Task<T> object make the code much cleaner
- nathanwdavis 15y agoFrom what I've heard, you can't use Task<T> for WinRT components that expose async methods. Instead you have to use IAsyncOperation as the return type. This limitation seems kind of annoying IMHO. Reference: Miguel de Icaza's blog post http://tirania.org/blog/archive/2011/Sep-15.html http://tirania.org/blog/archive/2011/Sep-15.html
- kenjackson 15y agoOnly if you're doing C++. If you're in C#/VB, you still use Task. http://msdn.microsoft.com/en-us/library/windows/apps/hh464924(v=VS.85).aspx#asynchronous_patterns_in__with_c_ http://msdn.microsoft.com/en-us/library/windows/apps/hh46492... I think that's because the TPL doesn't exist for C++.
- varunsrin 15y agoSo after toying with it for a couple of hours, here's what I've seen: I think if the method is named 'Async' (such as GetReplyAsync() *) , you can call it asynchronously with the new await in C#, and using Task<T> as the return type. Only methods that are lableled async implement the new 'await'. Some of the old .NET methods had 2 API's - synchronous & asyncrhonous. Some of the synchronous implementations, as pointed out in your link, have been deprecated. A few of the async methods I have seen (which do not have Async in the title), only accept the old IAsync/callback and do not work with await. Presumably, they do not implement the new C#5 style of async yet. Hopefully, they will at some point, because I'm a big fan of how clean & readable async C# can be now. Again I haven't explored C#5.0 thoroughly, these are just my first impressions.