您的位置:首页 > 编程语言 > C#

parallel programming. this causual litery nots represents my recent progress in parallel programming in c#.It`s interesting.

2015-07-05 00:15 651 查看
not to say extra words,let`s start the code.

pasted below:

using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

namespace paraldemo
{
class Program
{
static void Main(string[] args)
{
var watch = Stopwatch.StartNew();
watch.Start();
var a = 2;
var c = 0;
String[] names = new string[] { "a", "b" };
Parallel.ForEach(names, d => { Console.Write("paraeel:" + d); });
Parallel.For(1, 4, b => { c += b; });
Parallel.Invoke(() => { Console.WriteLine(1); }, () => Console.WriteLine(2));
Console.WriteLine(c);
watch.Stop();
Console.WriteLine(watch.ElapsedMilliseconds);
var task1 = Task.Factory.StartNew(() => { Console.WriteLine("test task factory"); });
task1.Wait(2000);
var task2 = Task.Factory.StartNew(e => Console.WriteLine("2" + e), c);
Task.WaitAll(task1, task2);
Parallel.Invoke(() => Console.WriteLine(1));
Task.Factory.StartNew(() => Console.WriteLine(2), new CancellationTokenSource().Token);
Console.ReadKey();
}
}
}


PLinq

from a in list.AsParallel
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: