多谢!
由于账户密码忘记了,一直不能登录。
其实,我的代码很简单:
画面上有一个spread,名称:ss1.
画面上有一个button,button的click事件的代码如下:
private void button1_Click(object sender, EventArgs e)
{
if (button1.Text == "start")
{
Control.CheckForIllegalCrossThreadCalls = false;
revThread = new System.Threading.Thread(writeSpread);
revThread.Start();
button1.Text ="end";
}
else
{
revThread.Abort();
revThread = null;
button1.Text = "start";
}
}
线程触发的函数程序如下所示:
private void writeSpread()
{
while (true)
{
rowCnt++;
if (rowCnt > 8) rowCnt = 0;
ss1.ActiveSheet.RowCount = rowCnt;
ss1_Sheet1.ColumnCount = rowCnt;
for (int i = 0; i < ss1.ActiveSheet.RowCount; i++)
{
for (int j = 0; j < ss1_Sheet1.ColumnCount; j++)
{
ss1_Sheet1.Cells[i, j].Text = (i * j).ToString();
}
}
Thread.Sleep(4000);
}
}
如果使用Thread.Sleep(4000);只能画一次,第二次就报错。不加上Thread.Sleep(4000);一次也画不了。
但是如果写textbox就没有问题,代码如下:
private void writeSpread()
{
while (true)
{
rowCnt++;
if (rowCnt > 80) rowCnt = 0;
textBox1.Text = rowCnt.ToString();
//ss1.ActiveSheet.RowCount = rowCnt;
//ss1_Sheet1.ColumnCount = rowCnt;
//for (int i = 0; i < ss1.ActiveSheet.RowCount; i++)
//{
// for (int j = 0; j < ss1_Sheet1.ColumnCount; j++)
// {
// ss1_Sheet1.Cells[i, j].Text = (i * j).ToString();
// }
//}
//Thread.Sleep(4000);
}
} |