我用C# winform多线程,窗口就假死,等到线程全部完成了才可以点击。请问要怎么才可以让窗口不假死。
下面是代码:privatevoidbutton1_Click(objectsender,EventArgse){Thread[]T=newThread[int.Parse...
下面是代码:
private void button1_Click(object sender, EventArgs e)
{
Thread[] T = new Thread[int.Parse(tb_xc.Text)];
for (int i = 0; i < int.Parse(tb_xc.Text); i++)
{
T[i] = new Thread(new ThreadStart(zxmysql));
T[i].Name = "xianc" + i.ToString();
T[i].Start();
T[i].Join(5000);
}
}
public int ss = 0;
public void zxmysql()
{
int shu = dataGridView1.RowCount;
try
{
lock (new object())
{
while (ss < shu)
{
string ip = dataGridView1.Rows[ss].Cells["ip"].Value.ToString();
string yh = dataGridView1.Rows[ss].Cells["zh"].Value.ToString();
string ma = dataGridView1.Rows[ss].Cells["mm"].Value.ToString();
bool pd = mysql(ip, yh, ma);
if (pd)
{
dataGridView1.Rows[ss].Cells["zt"].Value = "成功";
}
else
{
dataGridView1.Rows[ss].Cells["zt"].Value = "失败";
}
ss++;
zhixin.Text = ss.ToString();
}
}
}
catch
{ }
} 展开
private void button1_Click(object sender, EventArgs e)
{
Thread[] T = new Thread[int.Parse(tb_xc.Text)];
for (int i = 0; i < int.Parse(tb_xc.Text); i++)
{
T[i] = new Thread(new ThreadStart(zxmysql));
T[i].Name = "xianc" + i.ToString();
T[i].Start();
T[i].Join(5000);
}
}
public int ss = 0;
public void zxmysql()
{
int shu = dataGridView1.RowCount;
try
{
lock (new object())
{
while (ss < shu)
{
string ip = dataGridView1.Rows[ss].Cells["ip"].Value.ToString();
string yh = dataGridView1.Rows[ss].Cells["zh"].Value.ToString();
string ma = dataGridView1.Rows[ss].Cells["mm"].Value.ToString();
bool pd = mysql(ip, yh, ma);
if (pd)
{
dataGridView1.Rows[ss].Cells["zt"].Value = "成功";
}
else
{
dataGridView1.Rows[ss].Cells["zt"].Value = "失败";
}
ss++;
zhixin.Text = ss.ToString();
}
}
}
catch
{ }
} 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询