Threading and datagrid updates good idea?

  • Thread starter Thread starter VM
  • Start date Start date
V

VM

Is it possible that a thread that updates a grid give me problems? For some
reason, when the for loop is really big (30000+ rows in grid), I get "Object
reference not set to an instance of an object" or "External component has
thrown an exception" in some rows. And it always happens in the first few
records (rec. 30-40 when I'm stepping through the code or rec. 10-18 when
I'm not).

This is the code:

private void runProcess()
{
ThreadStart thr_markGrid = new ThreadStart(markAuditGrid);
Thread AZMThread = new Thread (thr_markGrid);
AZMThread.Start (); //starting the thread
}

private void markAuditGrid()
{
for(int i=0;i<iRows; i++) //iRows = 35000 - number of rows in grid
{
if(dataGrid_auditAddress.IsSelected(i) == true)
{
dataGrid_auditAddress[i,5] = "MARKED";
}
}
}
 
VM said:
Is it possible that a thread that updates a grid give me problems?

Yes. A DataGrid is a UI control, and as ever, you shouldn't do anything
to the UI except within the UI thread.
 
The reason I added this thread was so the application could respond to other
user events while the grid was beig updated. If I want to do this update
within the UI thread, how would you do it?
Any links that talk about working with the UI thread would be agreatly
appreciated.
 
VM said:
The reason I added this thread was so the application could respond to other
user events while the grid was beig updated. If I want to do this update
within the UI thread, how would you do it?

If you're basically doing a lot of stuff to the UI (and changing up to
35000 rows is a lot of stuff) then it's going to take some time.
Any links that talk about working with the UI thread would be agreatly
appreciated.

I don't have any links on hand, I'm afraid, although I'm sure there are
lots of pages around.
 
do what you'd normally do w/o spinning off another thread. if you are concerned that your program will temporarily freeze while doing all that work, then maybe you should rethink about displaying 35000 rows in the UI. :
----- VM wrote: ----

The reason I added this thread was so the application could respond to othe
user events while the grid was beig updated. If I want to do this updat
within the UI thread, how would you do it
Any links that talk about working with the UI thread would be agreatl
appreciated
 
Back
Top