首页 新闻 会员 周边

可变字段应用示例。并无书上所说效果。是我的问题还是书的问题、。?

0
悬赏园豆:5 [已关闭问题] 关闭于 2012-05-08 14:42

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;
                }
            }
        }
    }
}

C#
keyen的主页 keyen | 初学一级 | 园豆:135
提问于:2012-04-23 13:25
< >
分享
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册