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:
PLinq
from a in list.AsParallel
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
相关文章推荐
- C#如何播放视频,全屏且播放视频时候锁定鼠标和键盘
- 外部DLL文件在C#中导入使用问题
- C#课程设计:《猜猜看》游戏开发总结
- c#文本控件实现换行
- c#文本控件实现换行
- C#参数传递详解
- c#语言邮件发送参考代码
- c#第五次作业---正文提取
- C#开发人员能够可视化操作windows服务
- c#操作剪贴板
- C#选择文件对话框、选择路径对话框
- C#: 根据指定压缩比率压缩图片
- C#: 缩放图片
- C#: 旋转图片到正确位置
- C#类的继承,方法的重载和覆写
- c#访问存储过程
- C#图片处理示例(裁剪,缩放,清晰度,水印)
- C#常见组件总结
- C# 用递归方法取多个数组的相同元素
- c#课程设计---猜猜看游戏