├── code1.cs ├── code2.cs └── code3.cs /code1.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Threading; 3 | using System.Diagnostics; 4 | 5 | 6 | namespace ConsoleApp8{ 7 | 8 | class Program{ 9 | 10 | static void Main(string [] args ){ 11 | Stopwatch watch = new Stopwatch(); 12 | watch.Start(); 13 | for(int index=0; index<15; index++){ 14 | Console.WriteLine("Digging completed for" + index + "mtr. area"); 15 | Thread.Sleep(1000); 16 | } 17 | watch.Stop(); 18 | Console.WriteLine("Time required single handed: " + watch.Elapsed.Seconds); 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /code2.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Threading; 3 | using System.Threading.Tasks; 4 | using System.Diagnostics; 5 | 6 | namespace ConsoleApp{ 7 | class Program{ 8 | static void Main(){ 9 | Stopwatch watch = new Stopwatch(); 10 | watch.Start(); 11 | 12 | Parallel.For(0, 15, index=> { 13 | Console.WriteLine("Digging completed for" + index + "mtr. area"); 14 | Thread.Sleep(1000); 15 | } 16 | ); 17 | watch.Stop(); 18 | Console.WriteLine("Time required more than 1 persons digginng:{0} secounds" + watch.Elapsed.Seconds); 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /code3.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Threading; 3 | using System.Threading.Tasks; 4 | using System.Diagnostics; 5 | 6 | namespace ConsoleApp{ 7 | class Program{ 8 | static void Main(){ 9 | Stopwatch watch = new Stopwatch(); 10 | watch.Start(); 11 | var maxthread = new ParallelOptions(){ 12 | MaxDegreeOfParallelism = 2 13 | }; 14 | Parallel.For(0, 15, maxthread, index=> { 15 | Console.WriteLine("Digging completed for" + index + "mtr. area"); 16 | Thread.Sleep(1000); 17 | } 18 | ); 19 | watch.Stop(); 20 | Console.WriteLine("Time required more than 1 persons digginng:{0} secounds" + watch.Elapsed.Seconds); 21 | } 22 | } 23 | } 24 | --------------------------------------------------------------------------------