-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
31 lines (26 loc) · 894 Bytes
/
Program.cs
File metadata and controls
31 lines (26 loc) · 894 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
using static System.Console;
using System.Threading;
using System.Diagnostics;
/*
--------------------------------Task -------------------------------------------------------------
Task is nothing but an feature provided by the .NET framework which allows the ThradPool to manage all the
tasks without us doing it explicitly
Efficient way of creating threads where ThreadPool manages the threads efficiently
*/
static void Download(string fileName)
{
WriteLine("Downloading " + fileName);
Thread.Sleep(1000);
WriteLine("Downloaded " + fileName);
}
// creating a task and starting the task with a new method called Start()
var task1 = new Task(
() => Download("C++ by Walter Savitch ")
);
task1.Start();
// creating a task and running using task.Run()
var task2 = Task.Run(
() => Download("git scm book")
);
task1.Wait();
WriteLine("Main thread is running here");