fcamuso

Threads - A

Jun 3rd, 2021
674
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using System;
  2. using System.IO;
  3. using System.Threading;
  4.  
  5. namespace Threads_A
  6. {
  7.   class Program
  8.   {
  9.     static void metodoDaEseguire1()
  10.     {
  11.       int quanti= 100000000;
  12.       StreamWriter scrivi = new StreamWriter("g:\\file_thread.txt");
  13.        
  14.       for (int i = 0; i < quanti; i++)  scrivi.WriteLine("*");
  15.  
  16.       scrivi.Close();
  17.     }
  18.  
  19.     static void Main(string[] args)
  20.     {
  21.       DateTime start = DateTime.Now;
  22.  
  23.       Thread t1 = new Thread(metodoDaEseguire1);
  24.       t1.Start();
  25.  
  26.       int quanti = 100000000;
  27.       StreamWriter scrivi = new StreamWriter("h:\\file_main1.txt");
  28.       for (int i = 0; i < quanti; i++) scrivi.WriteLine("*");
  29.       scrivi.Close();
  30.  
  31.       //scrivi = new StreamWriter("file_main2.txt");
  32.       //for (int i = 0; i < quanti; i++) scrivi.WriteLine("+");
  33.       //scrivi.Close();
  34.  
  35.  
  36.       DateTime end = DateTime.Now;
  37.       Console.WriteLine((end - start).TotalMilliseconds);
  38.  
  39.  
  40.     }
  41.   }
  42. }
  43.  
RAW Paste Data