using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
namespace 可变字段应用示例
{
class Program
{
public static int result;
public static volatile bool finished; //不管有没有声明为volatile,结果一样.直接显示169
static void Thread2()
{
result = 169;
finished = true;
//Console.ReadKey();
}
static void Main(string[] args)
{
Console.Title = "可变字段应用示例";
result = 0; //这句是我自己加上去的!结果还是一样
finished = false;
//在一个新进程中执行Thread2()
new Thread(new ThreadStart(Thread2)).Start();
//等徐Thread2发信号,通过设置finished为true而得到结果
for (; ; )
{
if (finished)
{
Console.WriteLine("result={0}\n", result);
return;
}
}
}
}
}