Sachin Rajput

Sachin Rajput

  • NA
  • 4
  • 3.5k

C# program runs slowly on multiple instances

Jan 11 2017 2:14 AM

Now a days I'm practicing some programs of C#. I have an issue in this program.

I have created this program and it took 21 seconds to execute and my CPU usage is 20% and Ram usage is 1Gb max.

 
    1. static void Main(string[] args)  
    2.         {  
    3.             string str = Console.ReadLine();  
    4.   
    5.             if (str == "start")  
    6.             {  
    7.                // FrameRecord(40, 140, 780, 570, 2000, "E:\\imgCH1\\", 1);  
    8.   
    9.                 Stopwatch sw = new Stopwatch();  
    10.                 for (int i = 1; i < 200000; i++)  
    11.                 {  
    12.                     sw.Start();  
    13.   
    14.                     Console.WriteLine("Acccessed Value" + i.ToString());  
    15.                     Console.WriteLine("Time " + sw.ElapsedMilliseconds);  
    16.   
    17.                 }  
    18.   
    19.   
    20.             }  
    21.   
    22.   
    23.             Console.Read();  
    24.         }  
     

but when I create 2 instances of this It took 140 seconds and CPU usage is 20 % and Ram usage is 1GB max.

Can you please help me, how can I run multiple instances which will take 21 seconds but can utilize my Ram and CPU as maximum.


Answers (2)