fork download
  1. using System;
  2. using System.Threading.Tasks;
  3.  
  4. public class AsyncMethods {
  5. public async Task FirstMethodAsync() {
  6. Console.WriteLine("First async method started.");
  7. await Task.Delay(3000);
  8. Console.WriteLine("First async method completed.");
  9. }
  10.  
  11. public async Task SecondMethodAsync() {
  12. Console.WriteLine("Second async method started.");
  13. await Task.Delay(2000);
  14. Console.WriteLine("Second async method completed.");
  15. }
  16. }
  17.  
  18. public class SyncMethods {
  19. public void FirstMethod() {
  20. Console.WriteLine("First sync method started.");
  21. Task.Delay(3000).Wait();
  22. Console.WriteLine("First sync method completed.");
  23. }
  24.  
  25. public void SecondMethod() {
  26. Console.WriteLine("Second sync method started.");
  27. Task.Delay(2000).Wait();
  28. Console.WriteLine("Second sync method completed.");
  29. }
  30. }
  31.  
  32. public class Program {
  33. public static async Task Main() {
  34. AsyncMethods asyncMethods = new AsyncMethods();
  35. SyncMethods syncMethods = new SyncMethods();
  36.  
  37. syncMethods.FirstMethod();
  38. syncMethods.SecondMethod();
  39.  
  40. Task firstAsyncTask = asyncMethods.FirstMethodAsync();
  41. Task secondAsyncTask = asyncMethods.SecondMethodAsync();
  42.  
  43. await Task.WhenAll(firstAsyncTask, secondAsyncTask);
  44. Console.WriteLine("All methods have completed.");
  45. }
  46. }
Success #stdin #stdout 0.07s 32076KB
stdin
Standard input is empty
stdout
First sync method started.
First sync method completed.
Second sync method started.
Second sync method completed.
First async method started.
Second async method started.
Second async method completed.
First async method completed.
All methods have completed.