473,405 Members | 2,279 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,405 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 2573
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.