Event raised on different thread problem

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.
 
J

John Saunders

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top