Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Threading;
- using System.Threading.Tasks;
- namespace Parallel_Programming
- {
- internal class Program
- {
- private static void Main(string[] args)
- {
- Action<Action> measure = (body) =>
- {
- var startTime = DateTime.Now;
- body();
- Console.WriteLine("{0} {1}", DateTime.Now - startTime, Thread.CurrentThread.ManagedThreadId);
- };
- Action calcJob = () => { for (int i = 0; i < 350000000; i++);};
- measure(() =>
- {
- var tasks = new[]
- {
- Task.Factory.StartNew(() => measure(calcJob)),
- Task.Factory.StartNew(() => measure(calcJob)),
- Task.Factory.StartNew(() => measure(calcJob)),
- Task.Factory.StartNew(() => measure(calcJob)),
- Task.Factory.StartNew(() => measure(calcJob)),
- Task.Factory.StartNew(() => measure(calcJob))
- };
- Task.WaitAll(tasks);
- });
- // CTRL+F5
- }
- }
- }
- // Watch: https://www.youtube.com/watch?v=r1FbKiHYHcw
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement