Friday, November 14, 2014

Asynchronous Programming Concepts (.NET related)

Async execution - It's all about responsiveness.
Old code scenarios
To use WaitHandle from a Task.
Implement the APM pattern by FromAsync methods and "Tasks Forest"
Implement the EPM pattern by TaskCompletionSource.
Asynchronous Task
means the Threadless Task.
Asynchronous Tasks may have only the next statuses:
Fault, RunToCompletion, Cancelled.
Continuation for Asynchronous Tasks
Use the TaskCompletionSource<T> class.
async await
A syntactic sugar for awful amount of work.
A compiler's underground job.
A enumeration, try, finally, using and etc.
Users SynchronizationContext implicitly.
Unwrap multiple exceptions
The await will return only the first exception from a AggregateException.
There is a useful trick to unwrap multiple exceptions.
await task.ContinueWith(
    ( ) => { },
    TaskContinuationOptions.ExecuteSynchronously
);
var results = task.Result;
Multiple await
Preventing of lost exceptions with multiple await. (await like Parallel Programming fashion)
- Use trick from the Unwrap multiple exceptions.

No comments:

Post a Comment