Event raised on different thread problem

  • Thread starter Thread starter Kulgan
  • Start date Start date
K

Kulgan

Hi,

I have a dataset object that is binded to a datagrid in my main
thread. Now, when I add a row to the dataset object in a another
thread (since it may take awhile to complete), sometimes my
application will crash. I suspect this is because the ListChanged
event is raised on a different thread to the thread that my dataset
object was bound to the datagrid. My question is, how do I get around
this problem? I would think this would be a common problem, but
haven't found any answers.

Thanks in advance.
 
Kulgan said:
Hi,

I have a dataset object that is binded to a datagrid in my main
thread. Now, when I add a row to the dataset object in a another
thread (since it may take awhile to complete), sometimes my
application will crash. I suspect this is because the ListChanged
event is raised on a different thread to the thread that my dataset
object was bound to the datagrid. My question is, how do I get around
this problem? I would think this would be a common problem, but
haven't found any answers.

The answer is to add the row on the proper thread. Use dataGrid.Invoke.

John Saunders
 
Back
Top