I\'m trying to understand the purpose of TaskCompletionSource and its relation to async/threadless work. I think I have the general idea but I want to make sure
TaskCompletionSource is used to create Task objects that don't execute code.
They're used quite a bit by Microsoft's new async APIs - any time there's I/O-based asynchronous operations (or other non-CPU-based asynchronous operations, like a timeout). Also, any async Task method you write will use TCS to complete its returned Task.
I have a blog post Creating Tasks that discusses different ways to create Task instances. It's written from an async/await perspective (not a TPL perspective), but it still applies here.
Also see Stephen Toub's excellent posts:
TaskCompletionSource to await anything).Begin/End using TaskCompletionSource).