请高手指点下如何将入下方法在一个新的线程里执行
应用场景:有一个窗体,窗体上有一个 启动监视 按钮 具体内容需要不断刷新设备运行状态到窗体上,用
while(true)
{
}
会窗体不动 假死状态
有没有办法用线程的方法另外开一个线程来刷新这个表格 grid1
private void StartServer()
{
grid1.Cols = 9;
grid1.ExtendLastCol = true;
grid1.Rows = 17;
grid1.Cell(0, 1).Text = "EL-";
grid1.Cell(0, 2).Text = "EL+";
grid1.Cell(0, 3).Text = "ORG";
grid1.Cell(0, 4).Text = "STP";
grid1.Cell(0, 5).Text = "STA";
grid1.Cell(0, 6).Text = "SD-";
grid1.Cell(0, 7).Text = "SD+";
for (int k = 1; k <= 7; k++)
{
grid1.Column(k).Width = 50;
}
Image H = Resource.H12;
Image L = Resource.L12;
grid1.Images.Add(H, "H");
grid1.Images.Add(L, "L");
while (true)
{
for (int i = 0; i < 16; i++)
{
grid1.Cell(i, 1).Text = Dmc1000.d1000_get_axis_status(i).ToString();
for (int j = 0; j <= 6; j++)
{
grid1.Cell(i + 1, j + 1).Text = GetMotorStatusForAxis(i, j) ? "1" : "0";
if (grid1.Cell(i + 1, j + 1).Text == "1")
grid1.Cell(i + 1, j + 1).SetImage("H");
else
grid1.Cell(i + 1, j + 1).SetImage("L");
}
}
}
}
应用场景:有一个窗体,窗体上有一个 启动监视 按钮 具体内容需要不断刷新设备运行状态到窗体上,用
while(true)
{
}
会窗体不动 假死状态
有没有办法用线程的方法另外开一个线程来刷新这个表格 grid1
private void StartServer()
{
grid1.Cols = 9;
grid1.ExtendLastCol = true;
grid1.Rows = 17;
grid1.Cell(0, 1).Text = "EL-";
grid1.Cell(0, 2).Text = "EL+";
grid1.Cell(0, 3).Text = "ORG";
grid1.Cell(0, 4).Text = "STP";
grid1.Cell(0, 5).Text = "STA";
grid1.Cell(0, 6).Text = "SD-";
grid1.Cell(0, 7).Text = "SD+";
for (int k = 1; k <= 7; k++)
{
grid1.Column(k).Width = 50;
}
Image H = Resource.H12;
Image L = Resource.L12;
grid1.Images.Add(H, "H");
grid1.Images.Add(L, "L");
while (true)
{
for (int i = 0; i < 16; i++)
{
grid1.Cell(i, 1).Text = Dmc1000.d1000_get_axis_status(i).ToString();
for (int j = 0; j <= 6; j++)
{
grid1.Cell(i + 1, j + 1).Text = GetMotorStatusForAxis(i, j) ? "1" : "0";
if (grid1.Cell(i + 1, j + 1).Text == "1")
grid1.Cell(i + 1, j + 1).SetImage("H");
else
grid1.Cell(i + 1, j + 1).SetImage("L");
}
}
}
}