65
1
using System;
2
using System.Collections.Generic;
3
using System.Threading;
4
using System.Threading.Tasks;
5
6
public class Program
7
{
8
public static void Main()
9
{
10
Console.WriteLine("Hello World");
11
MyClass myClass1 =new MyClass();
12
MyClass myClass2 =new MyClass();
13
MyClass myClass3 =new MyClass();
14
15
Task<int> task1 = Task<int>.Factory.StartNew(()=>myClass1.DoWork());
16
Task<int> task2 = Task<int>.Factory.StartNew(()=>myClass2.DoWork());
17
Task<int> task3 = Task<int>.Factory.StartNew(()=>myClass3.DoWork());
18
19
int i1= task1.Result;
20
int i2 = task2.Result;
21
int i3 = task3.Result;
22
23
Console.WriteLine(i1);
24
Console.WriteLine(i2);
Cached Result
Hello World
Work started
Work Complete
Work started
Work Complete
Work started
Work Complete
8
16
24
Work started
Work Complete
Work started
Work Complete
Work started
Work Complete
8
16
24