日期:2014-05-17 浏览次数:20857 次
using System; using System.Threading; namespace ConsoleApplication1 { class Program { static void Main(string[] args) { var sum = 0; var eh = new ManualResetEvent(false); ThreadPool.QueueUserWorkItem(h => { for (var i = 2; i <= 100; i += 2) sum += i; eh.Set(); }); var sum2 = 0; for (var i = 1; i <= 100; i += 2) sum2 += i; eh.WaitOne(); Console.WriteLine("计算结果分别为{0}、{1},总计为{2}。", sum2, sum, sum2 + sum); Console.ReadKey(); } } }
------解决方案--------------------
http://www.cnblogs.com/xugang/archive/2008/04/06/1138856.html
------解决方案--------------------
如果有可能升级下.net版本吧
可以看看下面的文章或者blog:
Parallel Programming in the .NET Framework
http://msdn.microsoft.com/en-us/library/dd460693(v=vs.100).aspx
Parallel Computing
http://msdn.microsoft.com/en-us/vstudio/bb964701.aspx
Parallel Programming with .NET
http://blogs.msdn.com/b/pfxteam/