Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Diagnostics;
- using System.Threading;
- namespace parallelInvok
- {
- class Program
- {
- static void Main()
- {
- Stopwatch sw = new Stopwatch();
- sw.Start();
- try
- {
- Parallel.Invoke(
- Sum,
- () =>
- {
- Console.WriteLine("Method=beta, Thread={0}", Thread.CurrentThread.ManagedThreadId);
- },
- delegate ()
- {
- Console.WriteLine("Method=gamma, Thread={0}", Thread.CurrentThread.ManagedThreadId);
- }
- );
- }
- catch (AggregateException e)
- {
- Console.WriteLine("error");
- }
- sw.Stop();
- Console.WriteLine("Time: " + sw.ElapsedMilliseconds / 100.0);
- }
- static void Sum()
- {
- int N;
- Console.WriteLine("Введите N:");
- N = Convert.ToInt32(Console.ReadLine());
- double res = 0;
- for (double i = 0; i < N; i++)
- res += i / (i * i + 1);
- Console.WriteLine(res);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement