最笨的方法空循环
for(int i=0;i<=100;i++)
{
for(int j=0;j<=30000;j++) ;
}
Thread.Sleep(100);
Thread.Sleep()延迟
或多线程class Test
{
public static Int64 i = 0;
public static void Add()
{
for (int i = 0; i < 100000000; i++)
{
Interlocked.Increment(ref Test.i);
}
}
public static void Main(string[] args)
{
Thread t1 = new Thread(new ThreadStart(Test.Add));
Thread t2 = new Thread(new ThreadStart(Test.Add));
t1.Start();
t2.Start();
t1.Join();
t2.Join();
Console.WriteLine(Test.i.ToString());
Console.Read();
}
Thread.Sleep