fork download
  1. using static System.Console;
  2. using System.Threading;
  3. using System.Threading.Tasks;
  4. using System.Diagnostics;
  5.  
  6. public class Program {
  7. public static void Main(string[] args) {
  8. Task wait = ComDelay();
  9. WriteLine("O Main está executando algo após o Delay");
  10. wait.Wait();
  11. ComSleep();
  12. WriteLine("O Main está executando algo após o Sleep");
  13. }
  14.  
  15. static async Task ComDelay() {
  16. var sw = new Stopwatch();
  17. sw.Start();
  18. WriteLine("Início Delay");
  19. await Task.Delay(2000);
  20. WriteLine("Demorou {0}ms", sw.ElapsedMilliseconds);
  21. WriteLine("Fim Delay");
  22. }
  23.  
  24. static void ComSleep() {
  25. var sw = new Stopwatch();
  26. sw.Start();
  27. WriteLine("Início Sleep");
  28. Thread.Sleep(2000);
  29. WriteLine("Demorou {0}ms", sw.ElapsedMilliseconds);
  30. WriteLine("Fim Sleep");
  31. }
  32. }
  33.  
  34. //https://pt.stackoverflow.com/q/86014/101
Success #stdin #stdout 0.03s 18744KB
stdin
Standard input is empty
stdout
Início Delay
O Main está executando algo após o Delay
Demorou 2006ms
Fim Delay
Início Sleep
Demorou 2000ms
Fim Sleep
O Main está executando algo após o Sleep