The flow containing await in .NET 4.5 and Async CTP 4.0 can be stuck due to various reasons, e.g. since the remote client has not responded. Of course, WaitForAny, when we wait also for some timeout task is an obvious solution for recovery of the high-level flow. Still, this does not solve all possible problems.
I have the following questions:
What happens to the context of await which does not ever return? I understand that this will create memory leak. Am I right?
How can I check either in debugger or using the respective API how many dangling "awaiter"s exist in the application?
Is it possible to enumerate them globally?
If 3. is correct, is it possible to force cancellation the tasks for these *await*s (i.e. to clean up)?
Note: In question 4 I don't ask about cancellation items to be used during explicit task creation. I mean the case when the task was created indirectly:
async Task<bool> SomeTask()
{
await Something();
...
return true;
}
Motivation for this question:
- Trying to avoid memory leaks
- Trying to complication of the code with too many cases involving cancellation tokens
- In many situations the timeout is not known in advance for each low-level Task, but the high-level flow can use just recovery approach: "We are stuck? Never mind, just clean up and let's start over".
Task
s that never finish has an example where this won't cause a memory leak and I think that's the usual case. – Legge