I\'m attempting to programmatically chain asynchronous operations in C#4, such as Writes to a given Stream object. I originally did this \"manually\", hooking callbacks from one
My best idea so far is to chain the creation of the new write task, then use the Unwrap extension method to turn Task back into Task:
Task
public static Task ChainWrite(Stream stream, byte[] data, Task precedingTask) { return precedingTask.ContinueWith(x => CreateWriteTask(stream, data)).Unwrap(); }