当仅基于事件的API可用时(例如Windows Phone 8套接字),我主要使用它:
public Task<Args> SomeApiWrapper(){ TaskCompletionSource<Args> tcs = new TaskCompletionSource<Args>(); var obj = new SomeApi(); // will get raised, when the work is done obj.Done += (args) => { // this will notify the caller // of the SomeApiWrapper that // the task just completed tcs.SetResult(args); } // start the work obj.Do(); return tcs.Task;}因此,与C#5
async关键字一起使用时,它特别有用。



