Skip to content

Instantly share code, notes, and snippets.

@varun-r-boop
Created December 30, 2022 08:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save varun-r-boop/e98e458412c67ec2f3c58eb30735c2d5 to your computer and use it in GitHub Desktop.
Save varun-r-boop/e98e458412c67ec2f3c58eb30735c2d5 to your computer and use it in GitHub Desktop.
Task in C#:
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