Advertisement
ArchonHS

zalupa

Nov 24th, 2019
372
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.58 KB | None | 0 0
  1. using System;
  2. using System.Diagnostics;
  3. using System.Threading;
  4.  
  5. namespace ConsoleApp1
  6. {
  7.     class Program
  8.     {
  9.       public static double FirstThread(int Q, double N, double L, double t1, double t2, int m, int n, ref double[,] array)
  10.         {
  11.             for (int i = 1; i < n + 1; i+=2)
  12.             {
  13.                 Thread.Sleep(100);
  14.                 L = 0;
  15.                 for (int j = 1; j < m + 1; j++)
  16.                 {
  17.                     array[i, j] = Math.Pow(Q * i / 100, 2);
  18.                     Console.Write("Thr1 = ");
  19.                     Console.Write(array[i, j]);
  20.                     Console.Write(" ");
  21.                     L += array[i, j];
  22.                 }
  23.                 Console.WriteLine();
  24.                 t1 += L;
  25.             }
  26.             return t1;
  27.         }
  28.        public static double SecondThread(int Q, double N, double L, double t1, double t2, int m, int n, ref double[,] array)
  29.         {
  30.             for (int i = 2; i < n + 1; i+=2)
  31.             {
  32.                 Thread.Sleep(100);
  33.                 L = 0;
  34.                 for (int j = 1; j < m + 1; j++)
  35.                 {
  36.                     array[i, j] = Math.Pow(Q * i / 100, 2);
  37.                     Console.Write("Thr2 = ");
  38.                     Console.Write(array[i, j]);
  39.                     Console.Write(" ");
  40.                     L += array[i, j];
  41.                 }
  42.                 Console.WriteLine();
  43.                 t2 += L;
  44.             }
  45.             return t2;
  46.         }
  47.         static void Main(string[] args)
  48.         {
  49.             const int Q = 120;
  50.             int n = Convert.ToInt32(Console.ReadLine());
  51.             int m = Convert.ToInt32(Console.ReadLine());
  52.             double L = 0, N = 0;
  53.             double t1=0, t2=0;
  54.             double[,] array = new double[n + 2, m + 1];
  55.             var timer = Stopwatch.StartNew();
  56.             Thread thr1 = new Thread(() => FirstThread(Q, N, L, t1, t2, m, n, ref array));
  57.             Thread thr2 = new Thread(() => SecondThread(Q, N, L, t1, t2, m, n, ref array));
  58.             thr1.Start();
  59.             Thread.Sleep(10);
  60.             thr2.Start();
  61.             N = FirstThread(Q, N, L, t1, t2, m, n, ref array) + SecondThread(Q, N, L, t1, t2, m, n, ref array);
  62.             Console.WriteLine(N);
  63.             timer.Stop();
  64.             Thread.Sleep(1000);
  65.             Console.WriteLine("Выполнение метода заняло {0} мс", timer.ElapsedMilliseconds);
  66.             Console.WriteLine("Выполнение метода заняло {0} тиков", timer.ElapsedTicks);
  67.             Console.ReadKey();
  68.         }
  69.     }
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement