I have a method return void in a Web APP
public static void doSomething(){
}
I like it become fire and forget by using async in c# 5.0, how?
Btw, if the void doSomethingQuick() is short-run method, whats the most resource saving method to fire and forget?
If the void doSomethingSlow() is a long-running method, whats the most resource saving method to fire and forget?
There are three types of async methods:
Note that only the two last can be (a)waited on. Foo in this example is for fire and forget scenarios. You have to remember that
asyncin this case is just an indicator that the method may itself useawait. Hence you can declareasync void doSomethingQuick()andasync void doSomethingSlow(). Just because a method returns a task does not mean it executes on a seperate thread. It may return a completed task.