Since the async function return site is not caller, I assume this works, but I thought I would check that it is safe just in case. If this is not the case, why is this a stack overflow?
static async Task CheckAsync(TimeSpan recursiveTimer)
{
await Task.Delay(recursiveTimer);
CheckAsync(recursiveTimer);
}
Edit: I decided to just give it a try - it doesn't seem to overflow the stack (it now works on my machine - it is currently 210,000 on call). My alleged reason is that since the CheckAsync return site is not really CheckAsync, but instead somewhere in asynchronous plumbing. Therefore, when CheckAsync calls CheckAsync, it does not actually add the call stack through the usual function call mechanism, but instead places the function as an object in some kind of asynchronous “be started” queue that runs through some other threads controlling asynchronous functions.
For those who know this mechanism well: does it sound right?
source
share