private delegate void FlushClient();//代理 private void ThreadFunction() { if (this.textBox1.InvokeRequired) { FlushClient fc = new FlushClient(ThreadFunction); this.Invoke(fc); } else { string s = DateTime.Now.ToString("yyyy年MM月dd日 HH时mm分ss秒"); this.textBox1.Text = s; // this.label1.Text = s; } } private void CrossThreadFulush() { while (true) { Thread.Sleep(1000); ThreadFunction(); } } private void button1_Click(object sender, EventArgs e) { Thread th = new Thread(CrossThreadFulush); th.IsBackground = true; th.Start(); }
点击button1执行结果: