473,287 Members | 1,960 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,287 software developers and data experts.

Problem passing dataset between worker and UI thread

Working in VS2003, .Net 1.1

I'm working on a project where I compare data between two databases. This
is a lengthy process, and very data intensive, so I decided to create a
class, and thread out the work.

The order of work is as follows:
1. Retrieve the data from primary data source
2. Update UI with retrieved data - this is accomplished by passing a
dataset as an event parameter
3. Compare retrieved data to a secondary data source, updating UI
occasionally.

I'm running into 1 problem, and one weirdness, and I'm hoping someone can
guide me where I went wrong.

Problem: After data is bound to the datagrid and the compare to the
secondary data source is going on, if I scroll through the datagrid I get an
exception "Object reference not set to an instance of an object, and the
datagrid disappears, replaced by a big red X. StackTrace:

System.NullReferenceException: Object reference not set to an instance of an
object.
at System.Data.DataColumnPropertyDescriptor.GetValue( Object component)
at
System.Windows.Forms.DataGridColumnStyle.GetColumn ValueAtRow(CurrencyManager
source, Int32 rowNum)
at System.Windows.Forms.DataGridTextBoxColumn.Paint(G raphics g, Rectangle
bounds, CurrencyManager source, Int32 rowNum, Brush backBrush, Brush
foreBrush, Boolean alignToRight)
at
System.Windows.Forms.DataGridRelationshipRow.Paint CellContents(Graphics g,
Rectangle cellBounds, DataGridColumnStyle column, Brush backBr, Brush
foreBrush, Boolean alignToRight)
at System.Windows.Forms.DataGridRow.PaintData(Graphic s g, Rectangle
bounds, Int32 firstVisibleColumn, Int32 columnCount, Boolean alignToRight)
at System.Windows.Forms.DataGridRelationshipRow.Paint (Graphics g,
Rectangle bounds, Rectangle trueRowBounds, Int32 firstVisibleColumn, Int32
numVisibleColumns, Boolean alignToRight)
at System.Windows.Forms.DataGrid.PaintRows(Graphics g, Rectangle&
boundingRect)
at System.Windows.Forms.DataGrid.PaintGrid(Graphics g, Rectangle
gridBounds)
at System.Windows.Forms.DataGrid.OnPaint(PaintEventAr gs pe)
at System.Windows.Forms.Control.PaintWithErrorHandlin g(PaintEventArgs e,
Int16 layer, Boolean disposeEventArgs)
at System.Windows.Forms.Control.WmPaint(Message& m)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ControlNativeWindow.OnMessage (Message& m)
at System.Windows.Forms.ControlNativeWindow.WndProc(M essage& m)
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg,
IntPtr wparam, IntPtr lparam)

Weirdness:
While the compare to the secondary data source is going on, the thread's
dataset is being updated. But for some reason, the UI's dataset is being
updated as well. I thought that the UI would be working with a copy of the
thread's dataset when I do the BeginInvoke and create a new object, but it
obviously isn't. I have a feeling that my two issues are related, but I do
not have enough experience with threads to solve this.

I've provided a snip of the code so that you can understand how I'm making
the calls. If there is a better (more proper?) way of doing what I'm doing,
please educate me.

public class Verification //This is the class used by the worker thread
{
<snip>
private Verify()
{
dsVerification dsRetrievedData;

dsRetrievedData = RetrieveData();
DataUpdatedEvent (this, new StatusEventArgs(dsRetrievedData);
CompareToSecondary(dsRetrievedData);
}

<snip>

public delegate void DataUpdated(object sender, StatusEventArgs e);
public event DataUpdated DataUpdatedEvent;

} //End of Verification Class

private DataGrid dataGridVerification;
private Verifiy ioVerification;
private Thread ioThread;

private delegate void DataUpdatedDelegate(dsVerification adsRetrievedData);
private void DataUpdated (dsVerification adsRetrievedData)
{
dataGridVerification.DataSource = adsData.VerificationData;
}

private void ioVerification_DataUpdatedEvent(object sender, StatusEventArgs
e)
{
if (this.InvokeRequired)
{
this.BeginInvoke(new DataUpdatedDelegate(DataUpdated), new object[]
{e.Data});
return;
}

DataUpdated(e.Data);
}
Nov 25 '06 #1
2 2564
Carl,

Before we look to your problem, why such a difficult method. Normally it is
just getting the public or better internal properties from your dataset
class?

In my idea is what you are doing the standard way.

Cor

"Carl Heller" <a@b.cschreef in bericht
news:e$**************@TK2MSFTNGP02.phx.gbl...
Working in VS2003, .Net 1.1

I'm working on a project where I compare data between two databases. This
is a lengthy process, and very data intensive, so I decided to create a
class, and thread out the work.

The order of work is as follows:
1. Retrieve the data from primary data source
2. Update UI with retrieved data - this is accomplished by passing a
dataset as an event parameter
3. Compare retrieved data to a secondary data source, updating UI
occasionally.

I'm running into 1 problem, and one weirdness, and I'm hoping someone can
guide me where I went wrong.

Problem: After data is bound to the datagrid and the compare to the
secondary data source is going on, if I scroll through the datagrid I get
an exception "Object reference not set to an instance of an object, and
the datagrid disappears, replaced by a big red X. StackTrace:

System.NullReferenceException: Object reference not set to an instance of
an object.
at System.Data.DataColumnPropertyDescriptor.GetValue( Object component)
at
System.Windows.Forms.DataGridColumnStyle.GetColumn ValueAtRow(CurrencyManager
source, Int32 rowNum)
at System.Windows.Forms.DataGridTextBoxColumn.Paint(G raphics g,
Rectangle bounds, CurrencyManager source, Int32 rowNum, Brush backBrush,
Brush foreBrush, Boolean alignToRight)
at
System.Windows.Forms.DataGridRelationshipRow.Paint CellContents(Graphics g,
Rectangle cellBounds, DataGridColumnStyle column, Brush backBr, Brush
foreBrush, Boolean alignToRight)
at System.Windows.Forms.DataGridRow.PaintData(Graphic s g, Rectangle
bounds, Int32 firstVisibleColumn, Int32 columnCount, Boolean alignToRight)
at System.Windows.Forms.DataGridRelationshipRow.Paint (Graphics g,
Rectangle bounds, Rectangle trueRowBounds, Int32 firstVisibleColumn, Int32
numVisibleColumns, Boolean alignToRight)
at System.Windows.Forms.DataGrid.PaintRows(Graphics g, Rectangle&
boundingRect)
at System.Windows.Forms.DataGrid.PaintGrid(Graphics g, Rectangle
gridBounds)
at System.Windows.Forms.DataGrid.OnPaint(PaintEventAr gs pe)
at System.Windows.Forms.Control.PaintWithErrorHandlin g(PaintEventArgs e,
Int16 layer, Boolean disposeEventArgs)
at System.Windows.Forms.Control.WmPaint(Message& m)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ControlNativeWindow.OnMessage (Message& m)
at System.Windows.Forms.ControlNativeWindow.WndProc(M essage& m)
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg,
IntPtr wparam, IntPtr lparam)

Weirdness:
While the compare to the secondary data source is going on, the thread's
dataset is being updated. But for some reason, the UI's dataset is being
updated as well. I thought that the UI would be working with a copy of
the thread's dataset when I do the BeginInvoke and create a new object,
but it obviously isn't. I have a feeling that my two issues are related,
but I do not have enough experience with threads to solve this.

I've provided a snip of the code so that you can understand how I'm making
the calls. If there is a better (more proper?) way of doing what I'm
doing, please educate me.

public class Verification //This is the class used by the worker thread
{
<snip>
private Verify()
{
dsVerification dsRetrievedData;

dsRetrievedData = RetrieveData();
DataUpdatedEvent (this, new StatusEventArgs(dsRetrievedData);
CompareToSecondary(dsRetrievedData);
}

<snip>

public delegate void DataUpdated(object sender, StatusEventArgs e);
public event DataUpdated DataUpdatedEvent;

} //End of Verification Class

private DataGrid dataGridVerification;
private Verifiy ioVerification;
private Thread ioThread;

private delegate void DataUpdatedDelegate(dsVerification
adsRetrievedData);
private void DataUpdated (dsVerification adsRetrievedData)
{
dataGridVerification.DataSource = adsData.VerificationData;
}

private void ioVerification_DataUpdatedEvent(object sender,
StatusEventArgs e)
{
if (this.InvokeRequired)
{
this.BeginInvoke(new DataUpdatedDelegate(DataUpdated), new object[]
{e.Data});
return;
}

DataUpdated(e.Data);
}

Nov 25 '06 #2
There was no good reason. I changed my code so that the dataset is public.
I use the event to notify the UI thread that the dataset has changed. Upon
testing, I still have the same issues.

Any other ideas?

Thanks,

Carl.
"Cor Ligthert [MVP]" <no************@planet.nlwrote in message
news:eX**************@TK2MSFTNGP04.phx.gbl...
Carl,

Before we look to your problem, why such a difficult method. Normally it
is just getting the public or better internal properties from your dataset
class?

In my idea is what you are doing the standard way.

Cor

"Carl Heller" <a@b.cschreef in bericht
news:e$**************@TK2MSFTNGP02.phx.gbl...
>Working in VS2003, .Net 1.1

I'm working on a project where I compare data between two databases.
This is a lengthy process, and very data intensive, so I decided to
create a class, and thread out the work.

The order of work is as follows:
1. Retrieve the data from primary data source
2. Update UI with retrieved data - this is accomplished by passing a
dataset as an event parameter
3. Compare retrieved data to a secondary data source, updating UI
occasionally.

I'm running into 1 problem, and one weirdness, and I'm hoping someone can
guide me where I went wrong.

Problem: After data is bound to the datagrid and the compare to the
secondary data source is going on, if I scroll through the datagrid I get
an exception "Object reference not set to an instance of an object, and
the datagrid disappears, replaced by a big red X. StackTrace:

System.NullReferenceException: Object reference not set to an instance of
an object.
at System.Data.DataColumnPropertyDescriptor.GetValue( Object component)
at
System.Windows.Forms.DataGridColumnStyle.GetColum nValueAtRow(CurrencyManager
source, Int32 rowNum)
at System.Windows.Forms.DataGridTextBoxColumn.Paint(G raphics g,
Rectangle bounds, CurrencyManager source, Int32 rowNum, Brush backBrush,
Brush foreBrush, Boolean alignToRight)
at
System.Windows.Forms.DataGridRelationshipRow.Pain tCellContents(Graphics
g, Rectangle cellBounds, DataGridColumnStyle column, Brush backBr, Brush
foreBrush, Boolean alignToRight)
at System.Windows.Forms.DataGridRow.PaintData(Graphic s g, Rectangle
bounds, Int32 firstVisibleColumn, Int32 columnCount, Boolean
alignToRight)
at System.Windows.Forms.DataGridRelationshipRow.Paint (Graphics g,
Rectangle bounds, Rectangle trueRowBounds, Int32 firstVisibleColumn,
Int32 numVisibleColumns, Boolean alignToRight)
at System.Windows.Forms.DataGrid.PaintRows(Graphics g, Rectangle&
boundingRect)
at System.Windows.Forms.DataGrid.PaintGrid(Graphics g, Rectangle
gridBounds)
at System.Windows.Forms.DataGrid.OnPaint(PaintEventAr gs pe)
at System.Windows.Forms.Control.PaintWithErrorHandlin g(PaintEventArgs
e, Int16 layer, Boolean disposeEventArgs)
at System.Windows.Forms.Control.WmPaint(Message& m)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ControlNativeWindow.OnMessage (Message& m)
at System.Windows.Forms.ControlNativeWindow.WndProc(M essage& m)
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg,
IntPtr wparam, IntPtr lparam)

Weirdness:
While the compare to the secondary data source is going on, the thread's
dataset is being updated. But for some reason, the UI's dataset is being
updated as well. I thought that the UI would be working with a copy of
the thread's dataset when I do the BeginInvoke and create a new object,
but it obviously isn't. I have a feeling that my two issues are related,
but I do not have enough experience with threads to solve this.

I've provided a snip of the code so that you can understand how I'm
making the calls. If there is a better (more proper?) way of doing what
I'm doing, please educate me.

public class Verification //This is the class used by the worker thread
{
<snip>
private Verify()
{
dsVerification dsRetrievedData;

dsRetrievedData = RetrieveData();
DataUpdatedEvent (this, new StatusEventArgs(dsRetrievedData);
CompareToSecondary(dsRetrievedData);
}

<snip>

public delegate void DataUpdated(object sender, StatusEventArgs e);
public event DataUpdated DataUpdatedEvent;

} //End of Verification Class

private DataGrid dataGridVerification;
private Verifiy ioVerification;
private Thread ioThread;

private delegate void DataUpdatedDelegate(dsVerification
adsRetrievedData);
private void DataUpdated (dsVerification adsRetrievedData)
{
dataGridVerification.DataSource = adsData.VerificationData;
}

private void ioVerification_DataUpdatedEvent(object sender,
StatusEventArgs e)
{
if (this.InvokeRequired)
{
this.BeginInvoke(new DataUpdatedDelegate(DataUpdated), new object[]
{e.Data});
return;
}

DataUpdated(e.Data);
}


Nov 25 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Hardy Wang | last post by:
Hi, All I am wandering in 1.1 version of C#, how can I pass parameters to thread? In article http://www.yoda.arachsys.com/csharp/threadstart.html, it provides a way to pass one parameter. It...
2
by: bernardpace | last post by:
Hi, I am using the following code private void menuItemStart_Click(object sender, System.EventArgs e) { DataTable tbRand, tbShow; int randSize; ....
0
by: Andy Roxburgh | last post by:
Hi all, I'm trying to program a multithreaded application - it currently works, but I have two problems. I'm relatively new to VB.NET (C and VB6 are my things) so I'm a bit lost here. The code...
22
by: Arne | last post by:
How do I pass a dataset to a webservices? I need to submit a shoppingcart from a pocket PC to a webservice. What is the right datatype? II have tried dataset as a datatype, but I can't get it to...
10
by: ChrisB | last post by:
Coming from a C/C++ background, how would I pass a function pointer to a function? I want to write a function that handles certain thread spawning. Here's what I'm trying to invision: function(...
9
by: John Brown | last post by:
Hi there, Has anyone had any problems debugging a thread in VS 2005. If I put a breakpoint on a worker thread (the only one in the app) and then run the app two things happen: 1) It takes an...
19
by: Larry Smith | last post by:
Hi there, When I run the following on my app's primary thread: System.Type.GetType("System.Windows.Forms.Form") It works as expected. If I then launch a thread via the "BackgroundWorker"...
2
by: Jeff | last post by:
Hey ..NET 2.0 I'm developing an application which will perform some webservice calls and I believe having those calls in a separate thread may help the app run smoother No user are waiting...
1
by: raghudr | last post by:
Hi all, I am displaying a splash screen for which i have created a thread.Since my whole project is launched by windows service and that service will start automatically at the start of the...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: marcoviolo | last post by:
Dear all, I would like to implement on my worksheet an vlookup dynamic , that consider a change of pivot excel via win32com, from an external excel (without open it) and save the new file into a...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.