public async void method()
{
}
What is the use of this public async method? how it is used?
public async void method()
{
}
What is the use of this public async method? how it is used?
See: http://msdn.microsoft.com/en-us/library/hh156513.aspx
By using the async modifier, you specify that a method, lambda expression, or anonymous method is asynchronous. If you use this modifier on a method or expression, it's referred to as an async method.
public async Task<int> ExampleMethodAsync()
{
// . . . .
}
If you're new to asynchronous programming, you can find an introduction in Asynchronous Programming with Async and Await (C# and Visual Basic).
An async method provides a convenient way to do potentially long-running work without blocking the caller's thread. The caller (say, M1) of an async method can resume its work without waiting for the async method to finish. However, M1 typically uses the await keyword so that it returns immediately, allowing M1’s caller to resume work or return to the thread’s synchronization context (or message pump).
The async keyword is syntactical sugar for implementing asynchronous methods. This article explains the concept more http://msdn.microsoft.com/en-us/library/hh191443.aspx
It is using like the other methods. There is no difference except it is performing asynchronously. If you change return type to Task
or Task<T>
then it will be awaitable.