Here's a simple implementation:
SemaphoreSlim s = new SemaphoreSlim(0, 1); // No resource available.
Task<bool> w = s.WaitAsync(TimeSpan.FromSeconds(2)); // Timeout in 2 seconds.
s.Dispose(); // Dispose the semaphore earlier than timeout.
await w; // Try await the task. Should it throw or should it hang?
I was expecting it to throw ObjectDisposedException, but it hang on me instead. Could anyone please explain me why?