H
hs
Hi Everyone,
I'm having a few problems with events, threads, datagrid scroll and
refreshing (winform).
I have a datagrid whose datasource is a dataset. This dataset contains a
subset of the records requested. When a datagrid.scroll event is triggered -
1) I check the current subset (chunk) of data being displayed.
2) If there more chunks of data to come, create a thread, get next chunk of
data and place in a new dataset.
3) In main thread, merge this dataset with original dataset.
Now this works fine if I scroll by pressing the down arrow or just above the
arrow (which makes it scroll quicker). However, if I drag the scroll bar
down to the bottom (ie the quickest way to get to the bottom of the
datagrid) it freezes. It starts the thread (which is what i expect) to
retrieve the next chunk of data, but freezes.
I have an Application.DoEvents() in my code but doesn't solve the problem. I
think there's an event problem here but am not sure.
Any ideas?
thanks
private void dataGrid1_Scroll(object sender, EventArgs e)
{
DataGrid.HitTestInfo dgHti = dataGrid1.HitTest(42,42);
int iCurrentRow=dgHti.Row;
// Check (if Row near end of Last Chunk) if Fetch complete
if((iCurrentRow > (this.chunkLast * 750) + 225) && this.chunkNew > 0)
{
while(this.chunkFetch)
{
Thread.Sleep(250);
}
}
// Check if Fetch complete
if(!this.chunkFetch && this.chunkNew > 0)
{
this.ds.Merge(this.dsNew);
this.chunkLast ++;
this.chunkNew --;
this.dsNew.Tables.Clear();
}
// Chech if New Chunk Needed
if((iCurrentRow >= ((this.chunkLast ) * 750) )&& this.chunkNew == 0 &&
this.chunkLast < 4)
{
this.chunkNew ++;
this.chunkFetch = true;
this.dsNew = new DataSet();
Application.DoEvents();
dataGrid1.Refresh();
// Create Threads
Thread newThread = new Thread(new ThreadStart(this.FetchNextChunk));
// Start the thread
newThread.Start();
}
}
I'm having a few problems with events, threads, datagrid scroll and
refreshing (winform).
I have a datagrid whose datasource is a dataset. This dataset contains a
subset of the records requested. When a datagrid.scroll event is triggered -
1) I check the current subset (chunk) of data being displayed.
2) If there more chunks of data to come, create a thread, get next chunk of
data and place in a new dataset.
3) In main thread, merge this dataset with original dataset.
Now this works fine if I scroll by pressing the down arrow or just above the
arrow (which makes it scroll quicker). However, if I drag the scroll bar
down to the bottom (ie the quickest way to get to the bottom of the
datagrid) it freezes. It starts the thread (which is what i expect) to
retrieve the next chunk of data, but freezes.
I have an Application.DoEvents() in my code but doesn't solve the problem. I
think there's an event problem here but am not sure.
Any ideas?
thanks
private void dataGrid1_Scroll(object sender, EventArgs e)
{
DataGrid.HitTestInfo dgHti = dataGrid1.HitTest(42,42);
int iCurrentRow=dgHti.Row;
// Check (if Row near end of Last Chunk) if Fetch complete
if((iCurrentRow > (this.chunkLast * 750) + 225) && this.chunkNew > 0)
{
while(this.chunkFetch)
{
Thread.Sleep(250);
}
}
// Check if Fetch complete
if(!this.chunkFetch && this.chunkNew > 0)
{
this.ds.Merge(this.dsNew);
this.chunkLast ++;
this.chunkNew --;
this.dsNew.Tables.Clear();
}
// Chech if New Chunk Needed
if((iCurrentRow >= ((this.chunkLast ) * 750) )&& this.chunkNew == 0 &&
this.chunkLast < 4)
{
this.chunkNew ++;
this.chunkFetch = true;
this.dsNew = new DataSet();
Application.DoEvents();
dataGrid1.Refresh();
// Create Threads
Thread newThread = new Thread(new ThreadStart(this.FetchNextChunk));
// Start the thread
newThread.Start();
}
}