Azure-Samples / service-fabric-dotnet-getting-started

Get started with Service Fabric with these simple introductory sample projects.
MIT License
230 stars 329 forks source link

Thread.Sleep instead of Task.Delay? #84

Open Almantask opened 3 years ago

Almantask commented 3 years ago

I am surprised to see

Thread.Sleep(Timeout.Infinite);

and not

async Task Main...
...
await Task.Delay(Timeout.Infinite);

My concern is that, Thread.Sleep is a blocking operation. Won't it completely disable 1 thread from doing any work at all times? Won't Task.Delay give the thread back to the scheduler instead so it could do whatever it has to, while it simply await and not blocks?

Please let me know if the example is simply outdated or if it is justified. Thanks!

masnider commented 3 years ago

You are right. This could be replaced. Fair feedback that will be incorporated at some point.

This sample was prepared (long) before async main was supported by C#, and currently has not been ported up to a higher version of C# in order to maintain the greatest compatibility with older codebases and compilers. There are many improvements like this that we can make once we decide to move up the minimum language version we support.