async-ctp

Using async-await on .net 4

梦想的初衷 提交于 2019-12-16 20:12:14
问题 I'm currently starting to create an application that would profit a lot from C# 5's async-await feature. But I'm not sure which version of VS and of the async runtime to use. Looking at OS popularity charts, I'll need to support Windows XP for another three years or so. It looks like .net 4.5 runs only on newer versions of Windows, so I need to target .net 4.0. The development machines use Windows 7, so using a newer version of VS is not a problem. Now I need to first choose a compiler for

async Task.Run with MVVM

那年仲夏 提交于 2019-12-12 10:45:34
问题 I have been playing around with the new async CTP and MVVM patterns. I have been converting an old program of mine that was using a background worker and report progress to update a collection in my model. I have converted it to something like so TaskEx.Run(async () => { while (true) { // update ObservableCollection here } await TaskEx.Delay(500); }); In my view I bind to my viewmodel which exposes this observable collection. However, when my collection updates I get the following Exception

How to implement await without Async CTP

走远了吗. 提交于 2019-12-12 08:08:29
问题 How would you implement something that works similarly to the Async CTP await keyword? Is there a simple implementation that works like await in all cases, or does await require different implementations for different scenarios? 回答1: await always involves the same kind of transformation - but it's a pretty painful one. The library side of await isn't too complicated, but the tricky bit is that the compiler builds a state machine for you, allowing the continuation to jump back to the right

Gracefully handle background task when app tombstones

限于喜欢 提交于 2019-12-12 03:19:30
问题 I'm using the async ctp and have a task that runs in the background. It works great but throws an exception when it's running and the app is tombstoned. The exception is related to the database context being null. The docs say: When an application is tombstoned, the underlying database connections are closed. To return to its previous state after tombstoning, an application needs to redo any queries it had performed before it was tombstoned. I've tried using a cancellationtokesource but this

“Iterating” over an async method

谁都会走 提交于 2019-12-11 02:49:33
问题 A few related questions about the async CTP: I can iterate over an Iterator Block (an IEnumerable<T> yield-returning T ) using GetEnumerator() and then enumerator methods MoveNext() , and Current() . What is the analog for async methods? How can a non- async calling method to receive and process any await ed items and then ContinueWith() ? Can you provide a short example? I'm just not seeing it. Also, in this following example async method, MyAwaitable has a GetAwaiter() method. If GetAwaiter

Async generic delegate in C# 5.0

徘徊边缘 提交于 2019-12-11 02:26:14
问题 With Iterators, the following generic delegate is possible: public delegate IEnumerable<TOut> MyDelegate<TIn>(TIn param1); With the new async/await in C# 5.0 CTP, I expect to be able to create the analogous delegate as follows: public delegate async TOut MyDelegate<TIn>(TIn param1); I can't find the C# 5.0 spec or any help in this regard. Anyone know how this can be written or if it can't be written and why? Thanks! 回答1: async is an implementation detail, not an interface specification. An

The type 'System.Threading.Tasks.Task<TResult>' exists in both dlls

假装没事ソ 提交于 2019-12-11 01:36:25
问题 I get the following error while compiling the code. The type 'System.Threading.Tasks.Task' exists in both 'c:\Go\WP7CodeSamples\Pradna\packages\AsyncAwaitCTP.1.0\lib\sl4-wp71\AsyncCtpLibrary_Phone.dll' and 'c:\Go\WP7CodeSamples\Pradna\packages\System.Threading.Tasks.3.0.2-beta2\lib\sl4-wp71\System.Threading.Tasks.WP71.dll' not sure how to fix this issue. 回答1: You are using the old version of Async CTP. If you are still on Visual Studio 2010, download Visual Studio Async CTP (Version 3). If

Fire-forget and One-Way Calls in ASP.NET WebApi

跟風遠走 提交于 2019-12-10 13:49:51
问题 I totally understand that HTTP world is not the best choice for one-way calls and that WebApi is designed best for HTTP verbose communications. No doubt, WCF is the winner here. But, what if you already have an ApiController with a bunch of verbs exposed and at some point you needed to have a single one-way call too? And you don't want to host/maintain another service (WCF) for that. Task<HttpResponseMessage> response = client.PostAsJsonAsync<Log>("api/log", log) If you don't handle the

Task.Factory.StartNew() vs. TaskEx.Run()

偶尔善良 提交于 2019-12-08 16:02:51
问题 Task.Factory.StartNew() basically receives an Action and returns a Task. In The Async CTP we have TaskEx.Run() which also receives an Action and returns a Task. They seem to do that same thing. Why TaskEx.Run() was introduced ? 回答1: Anders Hejlsberg talked about that briefly in an interview on Channel9. Apparently, Task.Run is just a shorthand for Task.Factory.StartNew . Its still early CTP days so we're unsure that Task.Run will make it int. I personally hope it won't because it's kind of