首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

线程中如何启动 System.Windows.Forms.Timer timer

2013-12-28 
线程中怎么启动System.Windows.Forms.Timertimer,在线等用这种委托的方式不行this.label_currentTime.Invo

线程中怎么启动 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 = ""; ;//事件发生时间

就行了

热点排行