PC Review


Reply
Thread Tools Rate Thread

DataTable/DataGrid object and multiple threads

 
 
Dr. Len
Guest
Posts: n/a
 
      8th Aug 2004
Hi all!
In my app I implemented a separate worker thread that handles network
communication using Net.Sockets. It needs to make updates to a
DataTable object, which is displayed to the user by a DataGrid
control. The DataTable object is a 'public static' field instantiated
within context of the main thread.

The problem is that if I add a column to the DataTable from within the
worker thread (eg. different thread than where the DataTable and
DataGrid reside in), all columns suddenly disappear from the DataGrid
view for some reason;

Controller.dataTable.Columns.Add(new DataColumn("TestColumn"));

If I move this code to the main thread, it works fine. After adding
new column, I looked at dataTable with debugger and it seemed fine. So
the culprit must be the DataGrid control. Do I need some kind of
thread synchronization?
 
Reply With Quote
 
 
 
 
=?Utf-8?B?cmljaG1jdA==?=
Guest
Posts: n/a
 
      8th Aug 2004
Instead of trying to update the DataTable directly, raise an event from the
worker thread, passing the data in the event routine and let the main UI
thread handle updating the control.

Rich


"Dr. Len" wrote:

> Hi all!
> In my app I implemented a separate worker thread that handles network
> communication using Net.Sockets. It needs to make updates to a
> DataTable object, which is displayed to the user by a DataGrid
> control. The DataTable object is a 'public static' field instantiated
> within context of the main thread.
>
> The problem is that if I add a column to the DataTable from within the
> worker thread (eg. different thread than where the DataTable and
> DataGrid reside in), all columns suddenly disappear from the DataGrid
> view for some reason;
>
> Controller.dataTable.Columns.Add(new DataColumn("TestColumn"));
>
> If I move this code to the main thread, it works fine. After adding
> new column, I looked at dataTable with debugger and it seemed fine. So
> the culprit must be the DataGrid control. Do I need some kind of
> thread synchronization?
>

 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
DataTable -> DataView -> Sort -> DataGrid : need related DataTable index Diamonds Microsoft ADO .NET 4 28th Jun 2006 08:23 PM
Datatable updated by multiple threads yields datagrid problem Becker Microsoft Dot NET Framework Forms 1 19th Nov 2004 03:23 AM
Datatable updated by multiple threads yields datagrid problem Becker Microsoft VB .NET 0 18th Nov 2004 01:51 PM
filling a single datatable from multiple threads Uzi Baruch Microsoft ADO .NET 2 10th Mar 2004 02:25 PM
Binding a Business object to a datagrid with multiple levels Liam Ponder Microsoft ADO .NET 1 11th Aug 2003 10:18 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 06:18 PM.