多线程问题,程序运行时,还是单线程
多线程问题,程序运行时,还是单线程,窗体就像死了,请哪位老大指点一下,谢谢
最近一直看多线程,感觉高深莫测啊,左看右看,还是不太理解
窗体上有二个按钮,一个是把当前时间显示在窗体上,
另一个是向表中插入10000条记录,按下这个按钮同时,则把这个按钮的enable属性设置成false,等10000条数据插入到表中,再把它的enable属性设置 成true
delegate void testdele();
int intCount = 0;
TestUsingThread.testthread tt = new testthread();
public Form1()
{
InitializeComponent();
}
/// <summary>
/// 按钮事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btnListNumber_Click(object sender, EventArgs e)
{
ThreadStart ts = new ThreadStart(this.DeleCheck);
Thread td = new Thread(ts);
td.Start();
}
void DeleCheck()
{
testdele testmydele = new testdele(Add);
this.Invoke(testmydele);
}
/// <summary>
/// 向表中插入10000条记录
/// </summary>
void Add()
{
btnListNumber.Enabled = false;
for (int i = 0; i < 10000; i++)
{
if (tt.Add(i) > 0)
{
intCount++;
}
}
MessageBox.Show(intCount.ToString());
btnListNumber.Enabled = true;
}
/// <summary>
/// 把当前时间显示在标签上
/// </summary>
private void btnListLable_Click(object sender, EventArgs e)
{
labMessage.Text = System.DateTime.Now.ToString();
}