Advertisement
Guest User

Untitled

a guest
Oct 23rd, 2017
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.40 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using System.Diagnostics;
  7. using System.Threading;
  8.  
  9. namespace parallelInvok
  10. {
  11.     class Program
  12.     {
  13.         static void Main()
  14.         {
  15.             Stopwatch sw = new Stopwatch();
  16.             sw.Start();          
  17.             try
  18.             {
  19.                 Parallel.Invoke(
  20.                     Sum,
  21.                     () =>      
  22.                     {
  23.                         Console.WriteLine("Method=beta, Thread={0}", Thread.CurrentThread.ManagedThreadId);
  24.                     },
  25.                     delegate ()    
  26.                     {
  27.                         Console.WriteLine("Method=gamma, Thread={0}", Thread.CurrentThread.ManagedThreadId);
  28.                     }
  29.                 );
  30.             }
  31.             catch (AggregateException e)
  32.             {
  33.                 Console.WriteLine("error");
  34.             }
  35.             sw.Stop();
  36.            
  37.             Console.WriteLine("Time: " + sw.ElapsedMilliseconds / 100.0);
  38.         }
  39.  
  40.         static void Sum()
  41.         {
  42.             int N;
  43.             Console.WriteLine("Введите N:");
  44.             N = Convert.ToInt32(Console.ReadLine());
  45.             double res = 0;
  46.             for (double i = 0; i < N; i++)
  47.                 res += i / (i * i + 1);
  48.             Console.WriteLine(res);
  49.         }
  50.     }
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement