using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace Parallel
{
class Program
{
static void Main(string[] args)
{
Stopwatch watch = new Stopwatch();
watch.Start();
for (int i = 1; i <= 10; i++)
{
Console.WriteLine(i);
Thread.Sleep(500);
}
watch.Stop();
Console.WriteLine(watch.Elapsed);
Console.WriteLine("OK");
Console.ReadKey();
}
}
}
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace Parallel
{
class Program
{
static void Main(string[] args)
{
Stopwatch watch = new Stopwatch();
watch.Start();
for (int i = 1; i <= 10; i++)
{
Console.WriteLine(i);
Thread.Sleep(500);
}
watch.Stop();
Console.WriteLine(watch.Elapsed);
Console.WriteLine("OK");
Console.ReadKey();
}
}
}
C#并行编程示例
本文通过一个简单的C#程序示例介绍了如何使用并行编程技术。该程序使用了Stopwatch来计时,通过Thread.Sleep模拟长时间运行的任务,并通过Console输出了1到10的数字及总的执行时间。

被折叠的 条评论
为什么被折叠?



