async-ctp

can not await async lambda

懵懂的女人 提交于 2019-12-28 03:32:04
问题 Consider this, Task task = new Task (async () =>{ await TaskEx.Delay(1000); }); task.Start(); task.Wait(); The call task.Wait() does not wait for the task completion and the next line is executed immediately, but if I wrap the async lambda expression into a method call, the code works as expected. private static async Task AwaitableMethod() { await TaskEx.Delay(1000); } then (updated according comment from svick) await AwaitableMethod(); 回答1: In your lambda example, when you call task.Wait()

TaskEx.Yield(TaskScheduler)

半腔热情 提交于 2019-12-23 17:20:10
问题 Last month I asked the following question which resulted in my learning of TaskEx.Yield : Can async methods have expensive code before the first 'await'? However, I have since realized that this method actually submits all subsequent code to the ambient TaskScheduler . In true DI spirit, our team has agreed to avoid using ambient instances where possible, so I would like to know if it's possible to explicitly specify a TaskScheduler to use? Something like the following would be great: public

Install of Visual Studio Async CTP does not work

纵饮孤独 提交于 2019-12-23 12:42:33
问题 I have installed the latest Visual Studio Async CTP for Visual Studio 2010 (SP1 Refresh) package from here: http://msdn.microsoft.com/en-gb/vstudio/async.aspx The update shows up in my Windows 7 updates list. I do not see any other traces of it being installed (i.e. program list, registry). However, when I try to run some Silverlight demo code (SilverlightOccasionallyConnectedDemo) the async and await keywords are not recognized at all. I have references to the AsyncCtpLibrary_Silverlight in

Can the Async CTP be used with a portable library

邮差的信 提交于 2019-12-23 09:27:11
问题 I was looking to see if the Async CTP with a portable class library? 回答1: No. The Async CTP has different dlls for Desktop, Phone, Silverlight 4, and Silverlight 5. Hopefully in the near future, all these platforms will support Task (and async) natively, and then portable class libraries would be able to use async. Update: Microsoft.Bcl.Async can be installed for portable libraries targeting .NET 4.0/4.5, Windows Store apps, Silverlight 4/5, and Windows Phone 7.5/8.0 回答2: As a heads up, we've

How does the new async/await feature in C# 5 integrate with the message loop?

邮差的信 提交于 2019-12-23 07:57:14
问题 I've not had chance to check out the CTP of the new C# async/await feature, but here's something I was wondering: How does it integrate with the message loop? I assume that in a standard Windows application (Winforms, WPF) the continuations are called by sending messages to the application's message loop, using a Dispatcher or similar? What if I'm not using a standard windows message loop? For example in a GTK# application or in a console application (if indeed this feature could be of use at

How does C# 5 async return to main thread?

亡梦爱人 提交于 2019-12-21 05:37:18
问题 I was watching a vid about Async CTP and saw that if you call await from e.g. main thread , then the execution will continue from main thread when the work is completed. e.g //called from main thread var result = await SomeAsyncWork(); //this will execute in main thread also console.writeline(result) I had the naive impression that there would be a normal call back going on which would be executed on a worker thread. At some level that must be what is going on since you can wrap normal async

.NET 4 equivalent of Task.WhenAll()

做~自己de王妃 提交于 2019-12-20 17:41:14
问题 In .NET 4, is there any functional equivalent to .NET 4.5's System.Threading.Tasks.Task.WhenAll()? The goal is to wrap up multiple async tasks into a single one that is completed when all of its constituent tasks are done. 回答1: I think the closest thing built-in in .Net 4.0 is ContinueWhenAll(). You can make the continuationAction a simple tasks => tasks and use the returned Task . For performance reasons, you might want to use it with TaskContinuationOptions.ExecuteSynchronously . 回答2: In

.NET 4 equivalent of Task.WhenAll()

我们两清 提交于 2019-12-20 17:40:06
问题 In .NET 4, is there any functional equivalent to .NET 4.5's System.Threading.Tasks.Task.WhenAll()? The goal is to wrap up multiple async tasks into a single one that is completed when all of its constituent tasks are done. 回答1: I think the closest thing built-in in .Net 4.0 is ContinueWhenAll(). You can make the continuationAction a simple tasks => tasks and use the returned Task . For performance reasons, you might want to use it with TaskContinuationOptions.ExecuteSynchronously . 回答2: In

Is async recursion safe in C# (async ctp/.net 4.5)?

北慕城南 提交于 2019-12-20 17:26:22
问题 In C# with async ctp or the vs.net 2011 beta we can write recursive code like this: public async void AwaitSocket() { var socket = await this.AcceptSocketAsync(); //await socket and >>return<< to caller AwaitSocket(); //recurse, note that the stack will never be deeper than 1 step since await returns.. Handle(socket); // this will get called since "await" returns } In this specific sample, the code async waits for a tcp socket and once it has been accepted, it will recurse and async wait for

Is async recursion safe in C# (async ctp/.net 4.5)?

折月煮酒 提交于 2019-12-20 17:26:16
问题 In C# with async ctp or the vs.net 2011 beta we can write recursive code like this: public async void AwaitSocket() { var socket = await this.AcceptSocketAsync(); //await socket and >>return<< to caller AwaitSocket(); //recurse, note that the stack will never be deeper than 1 step since await returns.. Handle(socket); // this will get called since "await" returns } In this specific sample, the code async waits for a tcp socket and once it has been accepted, it will recurse and async wait for