Created
December 30, 2022 08:17
-
-
Save varun-r-boop/e98e458412c67ec2f3c58eb30735c2d5 to your computer and use it in GitHub Desktop.
Task in C#:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Threading.Tasks; | |
namespace TaskExample | |
{ | |
public class Program | |
{ | |
public static void Main(string[] args) | |
{ | |
// Create and start tasks | |
Task task1 = Task.Run(() => { | |
Console.WriteLine("Task 1 is running."); | |
System.Threading.Thread.Sleep(2000); | |
}); | |
Task task2 = Task.Run(() => { | |
Console.WriteLine("Task 2 is running."); | |
System.Threading.Thread.Sleep(1000); | |
}); | |
// Wait for all tasks to complete | |
Task.WaitAll(task1, task2); | |
Console.WriteLine("All tasks have completed."); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment