Note that all that a method marked async does is that it returns a Task<T> to the caller and then inside it it does the intrusive stuff (like IO, File Read etc) using await, meaning that it automatically makes it so that the thread is released when the intrusive stuff (marked with await) happens

Then when the result comes back, a new thread continues the execution to the end of the method

When consuming a Async method, either you can accept the task that it returns or you are free to await the response

With asp,net you have to explicitly opt into the async page lifecycle by setting async = true

Use HTTP Request instead of WebRequest API as it is completely Async

SIMPLY: AWAIT FREES UP THE THREAD UNTIL THE OPERATION IS FINISHED

ASYNC DOES NOT AFFECT THE CLIENT AT ALL

ALWAYS USE RegisterAsyncTask TO CALL ASYNC CODE

WEB API

JUST MARK THE METHOD AS ASYNC

ASYNC DOES NOT AFFECT THE CALLER AT ALL

EF 6 HAS ASYNC DB CALLS

CANCELLATION TOKENS

ALLOW CALLER TO TERMINATE A..

ASYNC DELAY: AWAIT TASK.DELAY(3000);

USE ALL 3 TOKENS TOGETHER IN SINGLE CANCELLATIONTOKEN OBJECT

PARALLELISM

Note that async and await are not about parallelism at all, but instead about freeing blocked threads

The way we can do parallelism is to not do async Task1; await t1; async t2;await t2; as this is sequential operation.

Instead kick off all the async calls one after the other and then simply wait all and then write the await code (without await keyword though)

OR Best create a List of Tasks : var tasks = new List<Task<string>>;

Then instead of await(whenAll), flush the response as soon as any task completes:

While(tasks.Any())

{

Var completed = await Task.WhenAny(tasks);

Tasks.Remove(completed);

If(!completed.IsFaulted)

Context.Response.Write(completed.Result);

Context.Response.Flush();

}

}

The last piece of optimization is to Flush asynchronously. But there is no FlushAsync method, so :