using System;
using System.Diagnostics;
using System.Threading.Tasks;
public class AsyncMethods {
public async Task FirstMethodAsync() {
Console.WriteLine("First async method started.");
Stopwatch stopwatch = Stopwatch.StartNew();
while (stopwatch.ElapsedMilliseconds < 1000) {}
stopwatch.Stop();
Console.WriteLine("First async method completed.");
}
public async Task SecondMethodAsync() {
Console.WriteLine("Second async method started.");
Stopwatch stopwatch = Stopwatch.StartNew();
while (stopwatch.ElapsedMilliseconds < 500) {}
stopwatch.Stop();
Console.WriteLine("Second async method completed.");
}
}
public class SyncMethods {
public void FirstMethod() {
Console.WriteLine("First sync method started.");
Stopwatch stopwatch = Stopwatch.StartNew();
while (stopwatch.ElapsedMilliseconds < 1000) {}
stopwatch.Stop();
Console.WriteLine("First sync method completed.");
}
public void SecondMethod() {
Console.WriteLine("Second sync method started.");
Stopwatch stopwatch = Stopwatch.StartNew();
while (stopwatch.ElapsedMilliseconds < 500) {}
stopwatch.Stop();
Console.WriteLine("Second sync method completed.");
}
}
public class Program {
public static async Task Main() {
AsyncMethods asyncMethods = new AsyncMethods();
SyncMethods syncMethods = new SyncMethods();
syncMethods.FirstMethod();
syncMethods.SecondMethod();
Task firstAsyncTask = asyncMethods.FirstMethodAsync();
Task secondAsyncTask = asyncMethods.SecondMethodAsync();
await Task.WhenAll(firstAsyncTask, secondAsyncTask);
Console.WriteLine("All methods have completed.");
}
}