private void Form1_Load(object sender, EventArgs e)
        {
            System.Threading.Timer t = new System.Threading.Timer(new TimerCallback((o) =>
                {
                    Invoke(new Action(() => this.label1.Text = System.DateTime.Now.ToString()));
                }), "", 4000, 100);
         }
 为什么label1显示的时间刷新几秒钟之后停止刷新了?

解决方案 »

  1.   

    System.Timers.Timer t2 = new System.Timers.Timer();
                t2.Elapsed += new System.Timers.ElapsedEventHandler((o, ee) =>
                    {
                        this.label2.Text = System.DateTime.Now.ToString();
                    });            t2.Interval = 100;
                t2.Enabled = true;
     使用System.Timers.Timer就没有问题。label2一直保持刷新。 使用System.Threading.Timer怎么不行?
      

  2.   

    估计还是那个线程/委托的问题,如果用Thread也是不能直接操作界面的
      

  3.   

    System.Threading.Timer 是基于线程池的,  Invoke....是使用UI线程,所以可以操作界面。
    this.label2.Text = System.DateTime.Now.ToString(); 这句改下: BeginInvoke(new Action(() => this.label2.Text = System.DateTime.Now.ToString()));  不改的话debug会出错,直接运行不出错。
    还是不清楚为什么使用System.Threading.Timer,label1显示的时间刷新几秒钟之后停止刷新了?
      

  4.   

    晕死,跨线程调用控件,直接这样用,有问题来找我线程中
    label2.Invoke(跨线程要执行的方法)线程外
    private void 要执行的方法
    {
        label2.text = System.DateTime.Now.ToString();
    }
      

  5.   

    System.Timers.Timer()是会重复执行的,当一次没有执行完而下一个回合又开始了,你说是不是刷新几次就卡死了?你怎么不试试单步调试看看是什么原因?
    System.Timers.Timer好像没什么用,也很少用到。