Sebz
October 28th, 2004, 08:04 AM
The code in Form1:
/// <summary>
/// Required designer variable.
Int32 lista __gc[];
System::Threading::Thread *watek1;
/// </summary>
...
Form1(void)
{ lista=new Int32 __gc[40];
int i=0;
while(i<40)
{lista[i]=1;
i++;
}
watek1=new System::Threading::Thread(new System::Threading::ThreadStart(this,Start));
InitializeComponent();
}
...
private: System::Void Form1_Load(System::Object * sender, System::EventArgs * e)
{watek1->Start();
}
...
And method of form1 that fills the dataSet....
public: void Start()
{while(1)
{int i=0;
int j=0;
while(i<40) //For every element decide what to do: remove, add or update
{DataRow * dr;
while(j<dataSet1->Tables->get_Item(0)->Rows->Count)
{if(dataSet1->Tables->get_Item(0)->Rows->get_Item(j)->get_Item(0)->ToString()->ToInt32(0)==i)
{dr=dataSet1->Tables->get_Item(0)->Rows->get_Item(j);
j=dataSet1->Tables->get_Item(0)->Rows->Count;
}
j++;
}
if(lista[i]==1) //If 1 we decide that element shoul be in the set
{if(dr) //If element already exists
{dr->set_Item(1,__box(1)); //->update of the second column of element (the same value for simple)
Application::DoEvents();
}
else //If element is not in the set
{DataRow * dr=this->dataSet1->Tables->get_Item(0)->NewRow();
dr->set_Item(0,i.ToString());
dr->set_Item(1,(1).ToString());
this->dataSet1->Tables->get_Item(0)->Rows->Add(dr);
Application::DoEvents();
}
}
else
{if(dr)
{dr->Delete();
Application::DoEvents();
}
}
i++;
}
}
}
What's the problem?
Form also has one dataGrid, dataSet with 1 table having 2 columns (first column is primary key)
Problem is that when this thread works program hangs up and exception is thrown (nullReference). I don't know what's happening. There's no errors in this code. Check this up.
The source of problem may be refreshing dataSet. It always makes a problem when number od element in set is biger then number of element that can be shown in the grid. Every time I try to scroll dataGrig or drag the Window of form1 the problem happens. Please help me. From 3 days I try to solve it and that doesn't works....
/// <summary>
/// Required designer variable.
Int32 lista __gc[];
System::Threading::Thread *watek1;
/// </summary>
...
Form1(void)
{ lista=new Int32 __gc[40];
int i=0;
while(i<40)
{lista[i]=1;
i++;
}
watek1=new System::Threading::Thread(new System::Threading::ThreadStart(this,Start));
InitializeComponent();
}
...
private: System::Void Form1_Load(System::Object * sender, System::EventArgs * e)
{watek1->Start();
}
...
And method of form1 that fills the dataSet....
public: void Start()
{while(1)
{int i=0;
int j=0;
while(i<40) //For every element decide what to do: remove, add or update
{DataRow * dr;
while(j<dataSet1->Tables->get_Item(0)->Rows->Count)
{if(dataSet1->Tables->get_Item(0)->Rows->get_Item(j)->get_Item(0)->ToString()->ToInt32(0)==i)
{dr=dataSet1->Tables->get_Item(0)->Rows->get_Item(j);
j=dataSet1->Tables->get_Item(0)->Rows->Count;
}
j++;
}
if(lista[i]==1) //If 1 we decide that element shoul be in the set
{if(dr) //If element already exists
{dr->set_Item(1,__box(1)); //->update of the second column of element (the same value for simple)
Application::DoEvents();
}
else //If element is not in the set
{DataRow * dr=this->dataSet1->Tables->get_Item(0)->NewRow();
dr->set_Item(0,i.ToString());
dr->set_Item(1,(1).ToString());
this->dataSet1->Tables->get_Item(0)->Rows->Add(dr);
Application::DoEvents();
}
}
else
{if(dr)
{dr->Delete();
Application::DoEvents();
}
}
i++;
}
}
}
What's the problem?
Form also has one dataGrid, dataSet with 1 table having 2 columns (first column is primary key)
Problem is that when this thread works program hangs up and exception is thrown (nullReference). I don't know what's happening. There's no errors in this code. Check this up.
The source of problem may be refreshing dataSet. It always makes a problem when number od element in set is biger then number of element that can be shown in the grid. Every time I try to scroll dataGrig or drag the Window of form1 the problem happens. Please help me. From 3 days I try to solve it and that doesn't works....