Sort datagrid (ThreadSystem.NullReferenceException in system.windows.forms.dll)

  • Thread starter Thread starter mahtan
  • Start date Start date
M

mahtan

Please help

I have the problem that when I change the data in a
Windows.Forms.DataGrid by a separate thread the following
Exception is thrown:

ThreadSystem.NullReferenceException in
system.windows.forms.dll

I can't catch this Exception and it only occurs when I
allow sorting in the grid and choose the changing column
to sort.

I tried several things like monitors, suspend layout etc.
but nothing helped.
In the Threads Window of Visual Studio I can see that
there is an extra thread with the highest priority. I
assume that this one do the sorting in the background and
causes this exception.

Is this a bug of the datagrid or not and has anybody a
suggestion to solve this problem?

I have written a small test application to reproduce this
behavior. If you are interested I can send it to you.

Thanks
Ben
 
Hi Ben,

No takers with just the message. I reckon you're gonna have to send that
Project.

Regards,
Fergus
 
Please help

I have the problem that when I change the data in a
Windows.Forms.DataGrid by a separate thread the following
Exception is thrown:

ThreadSystem.NullReferenceException in
system.windows.forms.dll

I can't catch this Exception and it only occurs when I
allow sorting in the grid and choose the changing column
to sort.

I tried several things like monitors, suspend layout etc.
but nothing helped.
In the Threads Window of Visual Studio I can see that
there is an extra thread with the highest priority. I
assume that this one do the sorting in the background and
causes this exception.

Is this a bug of the datagrid or not and has anybody a
suggestion to solve this problem?

I have written a small test application to reproduce this
behavior. If you are interested I can send it to you.

Thanks
Ben

Please do. But, I have to ask - are you trying to update the DataGrid
directly from the background thread? Because if you are, that is most
likely the source of your error. Windows forms controls are not thread
safe. All, except for 4, methods and properties must be called from the
GUI thread.
 
* Tom Shelton said:
Please do. But, I have to ask - are you trying to update the DataGrid
directly from the background thread? Because if you are, that is most
likely the source of your error. Windows forms controls are not thread
safe. All, except for 4, methods and properties must be called from the
GUI thread.

A good introduction to Windows Forms + Multithreading can be found here:

<http://www.devx.com/dotnet/Article/11358>
 
Back
Top