DataGrid Cross Thread Access

G

Guest

Hi,

I know the topic of cross-thread operations from the UI has been addressed
several times, but if anyone could provide some insight for my particular
scenario, I would be thankful...

Using Visual Basic (VS 2005 Beta 1)

In a Public class X, I have a TCP connection setup to parse and dump data
into a DataTable

On a Windows form I have a DataGrid and a button. When I click the button, a
new instance of the class X is created, the TCP connection is opened, and the
DataGrid's DataSource property is set to the the DataTable of class X.

I'm getting an 'Illegal Cross thread operation' being thrown from the class
saying that the DataGrid is being accessed on a thread other than the one it
was created on.

How do I code for this (seemingly simple) scenario?

Much thanks,

-Todd
 
K

Ken Tucker [MVP]

Hi,

http://msdn.microsoft.com/msdnmag/issues/04/05/BasicInstincts/

Ken
-------------------
"TFS" <Todd "at" ManagementAnalytics "dot" com> wrote in message
Hi,

I know the topic of cross-thread operations from the UI has been addressed
several times, but if anyone could provide some insight for my particular
scenario, I would be thankful...

Using Visual Basic (VS 2005 Beta 1)

In a Public class X, I have a TCP connection setup to parse and dump data
into a DataTable

On a Windows form I have a DataGrid and a button. When I click the button, a
new instance of the class X is created, the TCP connection is opened, and
the
DataGrid's DataSource property is set to the the DataTable of class X.

I'm getting an 'Illegal Cross thread operation' being thrown from the class
saying that the DataGrid is being accessed on a thread other than the one it
was created on.

How do I code for this (seemingly simple) scenario?

Much thanks,

-Todd
 
C

Cor Ligthert

TFS.

Be aware that the result of your thread in this case is only that it takes
some more time, however your user has the change to close the application.
(If you have set the right properties for that).

Than you can in my opinion create a seperated new dataset which you have
placed modaly and set that as the new datatasource when the thread ends.

Another option is in my opinion by first setting the datagrid.datasource to
nothing.

I hope this helps,

Cor
 

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