Questions tagged [async-ctp]

From Microsoft: The Visual Studio Async CTP (Version 3) extends Visual Studio 2010, providing a new, streamlined syntax for asynchronous development.

Async CTP Download

168 questions
342
votes
14 answers

How to call an async method from a getter or setter?

What'd be the most elegant way to call an async method from a getter or setter in C#? Here's some pseudo-code to help explain myself. async Task MyAsyncMethod() { return await DoSomethingAsync(); } public IEnumerable MyList { …
Doguhan Uluca
  • 6,933
  • 4
  • 38
  • 51
146
votes
4 answers

What's the difference between returning void and returning a Task?

In looking at various C# Async CTP samples I see some async functions that return void, and others that return the non-generic Task. I can see why returning a Task is useful to return data to the caller when the async operation completes,…
James Cadd
  • 12,136
  • 30
  • 85
  • 134
137
votes
5 answers

Using async-await on .net 4

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…
CodesInChaos
  • 106,488
  • 23
  • 218
  • 262
86
votes
14 answers

Task<> does not contain a definition for 'GetAwaiter'

Client iGame Channel = new ChannelFactory ( new BasicHttpBinding ( BasicHttpSecurityMode . None ) , new EndpointAddress ( new Uri ( "http://localhost:58597/Game.svc" ) ) ) . CreateChannel ( ); public Task Client (…
Ahmed Ghoneim
  • 6,834
  • 9
  • 49
  • 79
74
votes
2 answers

can not await async lambda

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…
kennyzx
  • 12,845
  • 6
  • 39
  • 83
70
votes
3 answers

Why use async requests instead of using a larger threadpool?

During the Techdays here in the Netherlands Steve Sanderson gave a presentation about C#5, ASP.NET MVC 4, and asynchronous Web. He explained that when requests take a long time to finish, all the threads from the threadpool become busy and new…
Wouter de Kort
  • 39,090
  • 12
  • 84
  • 103
45
votes
4 answers

Why does the async keyword exist

Browsing through the channel 9 msdn videos I found the following unanswered comment and was hoping someone could possibly explain it? I dont get the point of the async keyword. Why not just allow the await keyword anytime the method returns…
Maxim Gershkovich
  • 45,951
  • 44
  • 147
  • 243
40
votes
3 answers

CancellationToken UnRegister Action

I have a token for various tasks and I need to better manage their cancellation, to be notified of a cancellation I can use: token.Register(RegisterMethod); How can I remove this "subscription"? Is there any way to "UnRegister"? I thought about…
J. Lennon
  • 3,311
  • 4
  • 33
  • 64
22
votes
2 answers

What happens to an `awaiting` thread in C# Async CTP?

I've been reading about the new async await keyword and it sounds awesome, but there is one key question I haven't been able to find the answer for in any of the intro videos I've watched so far (I also read the whitepaper a while back). Suppose I…
devios1
  • 36,899
  • 45
  • 162
  • 260
21
votes
1 answer

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

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…
Roger Johansson
  • 22,764
  • 18
  • 97
  • 193
20
votes
2 answers

Async CTP and "finally"

Here's the code: static class AsyncFinally { static async Task Func( int n ) { try { Console.WriteLine( " Func: Begin #{0}", n ); await TaskEx.Delay( 100 ); Console.WriteLine( " …
Soonts
  • 20,079
  • 9
  • 57
  • 130
20
votes
3 answers

Run an async function in another thread

I'm evaluating the Async CTP. How can I begin execution of an async function on another thread pool's thread? static async Task Test() { // Do something, await something } static void Main( string[] args ) { // Is there more elegant way to…
Soonts
  • 20,079
  • 9
  • 57
  • 130
17
votes
3 answers

Code Contracts and Asynchrony

What is the recommended way for adding postconditions to async methods which return Task? I have read the following suggestion: http://social.msdn.microsoft.com/Forums/hu-HU/async/thread/52fc521c-473e-4bb2-a666-6c97a4dd3a39 The post suggests…
17
votes
3 answers

How to write simple async method?

Using latest CTP5 with async/await keywords, I wrote some code, which apparently cannot compile: class Program { public class MyClass { async public Task Test() { var result = await…
ghord
  • 13,260
  • 6
  • 44
  • 69
16
votes
4 answers

Why was "SwitchTo" removed from Async CTP / Release?

I tried to use the SwitchTo method today to switch to the GUI thread, and found that the example I lifted it from does not work, simply because the method is not there. I then found this blurb here: The reason we got rid of it was because it was so…
Lasse V. Karlsen
  • 380,855
  • 102
  • 628
  • 825
1
2 3
11 12