When to use the wait keyword

If a method is declared as "async" when we call this method, we may or may not use it. I want to know when to use it and what is the effect of using it.

+6
source share
2 answers

The async keyword is just an indicator to the compiler that a method may contain a wait statement.

There's an interesting post by Eric Lippert explaining design choices.

The requirement "async" means that we can immediately fix all backward compatibility issues; any method containing an expectation should be the code of the "new build", and not the code of the "old job", because the code of the "old job" never had an async modifier.

http://blogs.msdn.com/b/ericlippert/archive/2010/11/11/whither-async.aspx

+2
source

A labeled asynchronous method is commonly used to indicate suspension points. The wait statement tells the compiler that the async method cannot continue this point until the expected asynchronous process is complete. In the meantime, control returns to the caller of the async method.

in other words, if you are performing asyncronius programming and want to run a specific thread task at the same time, you would like to rely on async and wait

more detailed explanations here

http://msdn.microsoft.com/en-us/library/vstudio/hh191443.aspx

+1
source

All Articles