fanronghua
-木头人- 第1楼 回复于2005-9-22 17:22:19
--------------------------------------------------------------------------------简化一下:
namespace WinAgilentSoftWare
{
public class MainForm : System.Windows.Forms.Form
{
//定义公共变量
ServerClass serverObject ;
Thread InstanceCaller;
static DataTable TTABLE ;
public class ServerClass
{
//------------动态的线程服务对象--------------------------------------------
public MainForm mainForm;
public void InstanceMethod()
{
Console.WriteLine("服务线程正在运行.");
while (ThreadFlag == 0 )
{
DataRow newRow1 = TTABLE.NewRow();
newRow1[0]=i;
newRow1[1]=i + 1;
newRow1[2]=i + 2;
newRow1[3]=i + 3;
newRow1[4]=i + 4;
newRow1[5]=i + 5;
newRow1[6]=i + 6;
newRow1[7]=i + 7;
newRow1[8]=i + 8;
TTABLE.Rows.Add(newRow1);
mainForm.DataGrid.CurrentCell = new DataGridCell(i+1,1);
}
-木头人- 第1楼 回复于2005-9-22 17:22:19
--------------------------------------------------------------------------------简化一下:
namespace WinAgilentSoftWare
{
public class MainForm : System.Windows.Forms.Form
{
//定义公共变量
ServerClass serverObject ;
Thread InstanceCaller;
static DataTable TTABLE ;
public class ServerClass
{
//------------动态的线程服务对象--------------------------------------------
public MainForm mainForm;
public void InstanceMethod()
{
Console.WriteLine("服务线程正在运行.");
while (ThreadFlag == 0 )
{
DataRow newRow1 = TTABLE.NewRow();
newRow1[0]=i;
newRow1[1]=i + 1;
newRow1[2]=i + 2;
newRow1[3]=i + 3;
newRow1[4]=i + 4;
newRow1[5]=i + 5;
newRow1[6]=i + 6;
newRow1[7]=i + 7;
newRow1[8]=i + 8;
TTABLE.Rows.Add(newRow1);
mainForm.DataGrid.CurrentCell = new DataGridCell(i+1,1);
}
//创建一个对象
serverObject = new ServerClass();
//创建一个线程
serverObject.mainForm = this;
MainForm aa = new MainForm();
InstanceCaller = new Thread(new ThreadStart(serverObject.InstanceMethod));
//线程开始执行
InstanceCaller.Start();
怀疑是显示的界面有些东西,比如是不是加入30多之后,就显示不开了?
或是你改变了ThreadFlag ?
线程运行起来,走了30多,所以不会是这个出问题的,有问题早就出了,对吧。
我想是这个
mainForm.DataGrid.CurrentCell = new DataGridCell(i+1,1);
我把他改了,还是有问题呀。
DataRow TempDataRow = TempDataTable.NewRow();//难道这个有问题??
TempDataRow[0] = i;
TempDataTable.Rows.Add(TempDataRow);
this.DataGrid.CurrentRowIndex = i-1 ;