刚刚学习C#,想创建一个时间的窗口,但是运行不了说是Thread没有声明,不知道怎么改,下面是程序的具体,请大神们看看 谢谢
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace 多线运行
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
delegate void SetTextCallback(string text);
private void button1_Click(object sender, EventArgs e)
{
Thread t = new Thread(new ThreadStart(Show));
t.Start();
}
private void SetText(string text)
{
if (textBox1.InvokeRequired)
{
SetTextCallback d = new SetTextCallback(SetText);
this.Invoke(d, new object[] { text });
}
else
{
textBox1.Text = text;
}
}
private void Show()
{
for (int i = 0; i < 500; i++)
{
SetText(DateTime.Now.ToString());
Thread.Sleep(100);
}
}
}
}
using System.Threading;