日期:2014-05-17  浏览次数:20725 次

线程中怎么启动 System.Windows.Forms.Timer timer,在线等
用这种委托的方式不行

this.label_currentTime.Invoke(
                                new MethodInvoker(
                                delegate
                                {
                                    label_currentTime.Text = ""; ;//事件发生时间
                                }));

因为 timer没有Invoke属性

------解决方案--------------------
delegate void SetButCallback(bool state);
        private void SetTIME(bool state)
        {
            if (this.InvokeRequired)
            {
                SetButCallback d = new SetButCallback(SetTIME);
                this.Invoke(d, new object[] { state });
            }
            else
            {
if(state=true)
{
启动timer
}
                                                }
        }
------解决方案--------------------
什么需求,我看你的需求就是先试下当前的时间嘛!
label_currentTime.Text = System.DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");//事件发生时间

直接调用就行了,不需要线程和委托啊!
------解决方案--------------------
Timer控件就不需要这个啦,直接在Tick绑定的方法里面写
label_currentTime.Text = ""; ;//事件发生时