While trying to figure out the new (maybe not so new now, but new to me, anyway) Task asynchronous programming in C#, I ran into a problem that took me a bit to fig
After much screwing around and hair-pulling I finally decided to get rid of the async lambda and just use the System.Threading.Thread.Sleep method, to see if that made any difference.
The new code ended up like this:
Random rng = new Random((int)DateTime.UtcNow.Ticks);
int delay = rng.Next(1500, 15000);
Task
Note: Due to removing the async keyword from the lambda method, the task type can now be simply Task rather than Task - you can see this change in the code above.
And, voila! It worked! I got the 'Finished waiting.' message AFTER the task completed.
Alas, I remember reading somewhere that you shouldn't use System.Threading.Thread.Sleep() in your Task code. Can't remember why; but as it was just for testing and most tasks will actually be doing something that takes time rather than pretending to be doing something that takes time, this shouldn't really be an issue.
Hopefully this helps some people out. I'm definitely not the best programmer in the world (or even close) and my code is probably not great, but if it helps someone, great! :)
Thanks for reading.
Edit: The other answers to my question explain why I had the problem I did and this answer only solved the problem by mistake. Changing to Thread.Sleep(x) had no effect. Thank you to all the people who answered and helped me out!