473,756 Members | 2,187 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.NullRefe renceException: Object reference not set to an instance of an
object.
at System.Data.Dat aColumnProperty Descriptor.GetV alue(Object component)
at
System.Windows. Forms.DataGridC olumnStyle.GetC olumnValueAtRow (CurrencyManage r
source, Int32 rowNum)
at System.Windows. Forms.DataGridT extBoxColumn.Pa int(Graphics g, Rectangle
bounds, CurrencyManager source, Int32 rowNum, Brush backBrush, Brush
foreBrush, Boolean alignToRight)
at
System.Windows. Forms.DataGridR elationshipRow. PaintCellConten ts(Graphics g,
Rectangle cellBounds, DataGridColumnS tyle column, Brush backBr, Brush
foreBrush, Boolean alignToRight)
at System.Windows. Forms.DataGridR ow.PaintData(Gr aphics g, Rectangle
bounds, Int32 firstVisibleCol umn, Int32 columnCount, Boolean alignToRight)
at System.Windows. Forms.DataGridR elationshipRow. Paint(Graphics g,
Rectangle bounds, Rectangle trueRowBounds, Int32 firstVisibleCol umn, Int32
numVisibleColum ns, Boolean alignToRight)
at System.Windows. Forms.DataGrid. PaintRows(Graph ics g, Rectangle&
boundingRect)
at System.Windows. Forms.DataGrid. PaintGrid(Graph ics g, Rectangle
gridBounds)
at System.Windows. Forms.DataGrid. OnPaint(PaintEv entArgs pe)
at System.Windows. Forms.Control.P aintWithErrorHa ndling(PaintEve ntArgs e,
Int16 layer, Boolean disposeEventArg s)
at System.Windows. Forms.Control.W mPaint(Message& m)
at System.Windows. Forms.Control.W ndProc(Message& m)
at System.Windows. Forms.ControlNa tiveWindow.OnMe ssage(Message& m)
at System.Windows. Forms.ControlNa tiveWindow.WndP roc(Message& m)
at System.Windows. Forms.NativeWin dow.Callback(In tPtr 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();
DataUpdatedEven t (this, new StatusEventArgs (dsRetrievedDat a);
CompareToSecond ary(dsRetrieved Data);
}

<snip>

public delegate void DataUpdated(obj ect sender, StatusEventArgs e);
public event DataUpdated DataUpdatedEven t;

} //End of Verification Class

private DataGrid dataGridVerific ation;
private Verifiy ioVerification;
private Thread ioThread;

private delegate void DataUpdatedDele gate(dsVerifica tion adsRetrievedDat a);
private void DataUpdated (dsVerification adsRetrievedDat a)
{
dataGridVerific ation.DataSourc e = adsData.Verific ationData;
}

private void ioVerification_ DataUpdatedEven t(object sender, StatusEventArgs
e)
{
if (this.InvokeReq uired)
{
this.BeginInvok e(new DataUpdatedDele gate(DataUpdate d), new object[]
{e.Data});
return;
}

DataUpdated(e.D ata);
}
Nov 25 '06 #1
2 2595
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$******** ******@TK2MSFTN GP02.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.NullRefe renceException: Object reference not set to an instance of
an object.
at System.Data.Dat aColumnProperty Descriptor.GetV alue(Object component)
at
System.Windows. Forms.DataGridC olumnStyle.GetC olumnValueAtRow (CurrencyManage r
source, Int32 rowNum)
at System.Windows. Forms.DataGridT extBoxColumn.Pa int(Graphics g,
Rectangle bounds, CurrencyManager source, Int32 rowNum, Brush backBrush,
Brush foreBrush, Boolean alignToRight)
at
System.Windows. Forms.DataGridR elationshipRow. PaintCellConten ts(Graphics g,
Rectangle cellBounds, DataGridColumnS tyle column, Brush backBr, Brush
foreBrush, Boolean alignToRight)
at System.Windows. Forms.DataGridR ow.PaintData(Gr aphics g, Rectangle
bounds, Int32 firstVisibleCol umn, Int32 columnCount, Boolean alignToRight)
at System.Windows. Forms.DataGridR elationshipRow. Paint(Graphics g,
Rectangle bounds, Rectangle trueRowBounds, Int32 firstVisibleCol umn, Int32
numVisibleColum ns, Boolean alignToRight)
at System.Windows. Forms.DataGrid. PaintRows(Graph ics g, Rectangle&
boundingRect)
at System.Windows. Forms.DataGrid. PaintGrid(Graph ics g, Rectangle
gridBounds)
at System.Windows. Forms.DataGrid. OnPaint(PaintEv entArgs pe)
at System.Windows. Forms.Control.P aintWithErrorHa ndling(PaintEve ntArgs e,
Int16 layer, Boolean disposeEventArg s)
at System.Windows. Forms.Control.W mPaint(Message& m)
at System.Windows. Forms.Control.W ndProc(Message& m)
at System.Windows. Forms.ControlNa tiveWindow.OnMe ssage(Message& m)
at System.Windows. Forms.ControlNa tiveWindow.WndP roc(Message& m)
at System.Windows. Forms.NativeWin dow.Callback(In tPtr 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();
DataUpdatedEven t (this, new StatusEventArgs (dsRetrievedDat a);
CompareToSecond ary(dsRetrieved Data);
}

<snip>

public delegate void DataUpdated(obj ect sender, StatusEventArgs e);
public event DataUpdated DataUpdatedEven t;

} //End of Verification Class

private DataGrid dataGridVerific ation;
private Verifiy ioVerification;
private Thread ioThread;

private delegate void DataUpdatedDele gate(dsVerifica tion
adsRetrievedDat a);
private void DataUpdated (dsVerification adsRetrievedDat a)
{
dataGridVerific ation.DataSourc e = adsData.Verific ationData;
}

private void ioVerification_ DataUpdatedEven t(object sender,
StatusEventArgs e)
{
if (this.InvokeReq uired)
{
this.BeginInvok e(new DataUpdatedDele gate(DataUpdate d), new object[]
{e.Data});
return;
}

DataUpdated(e.D ata);
}

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******** ******@TK2MSFTN GP04.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$******** ******@TK2MSFTN GP02.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.NullRef erenceException : Object reference not set to an instance of
an object.
at System.Data.Dat aColumnProperty Descriptor.GetV alue(Object component)
at
System.Windows .Forms.DataGrid ColumnStyle.Get ColumnValueAtRo w(CurrencyManag er
source, Int32 rowNum)
at System.Windows. Forms.DataGridT extBoxColumn.Pa int(Graphics g,
Rectangle bounds, CurrencyManager source, Int32 rowNum, Brush backBrush,
Brush foreBrush, Boolean alignToRight)
at
System.Windows .Forms.DataGrid RelationshipRow .PaintCellConte nts(Graphics
g, Rectangle cellBounds, DataGridColumnS tyle column, Brush backBr, Brush
foreBrush, Boolean alignToRight)
at System.Windows. Forms.DataGridR ow.PaintData(Gr aphics g, Rectangle
bounds, Int32 firstVisibleCol umn, Int32 columnCount, Boolean
alignToRight )
at System.Windows. Forms.DataGridR elationshipRow. Paint(Graphics g,
Rectangle bounds, Rectangle trueRowBounds, Int32 firstVisibleCol umn,
Int32 numVisibleColum ns, Boolean alignToRight)
at System.Windows. Forms.DataGrid. PaintRows(Graph ics g, Rectangle&
boundingRect )
at System.Windows. Forms.DataGrid. PaintGrid(Graph ics g, Rectangle
gridBounds)
at System.Windows. Forms.DataGrid. OnPaint(PaintEv entArgs pe)
at System.Windows. Forms.Control.P aintWithErrorHa ndling(PaintEve ntArgs
e, Int16 layer, Boolean disposeEventArg s)
at System.Windows. Forms.Control.W mPaint(Message& m)
at System.Windows. Forms.Control.W ndProc(Message& m)
at System.Windows. Forms.ControlNa tiveWindow.OnMe ssage(Message& m)
at System.Windows. Forms.ControlNa tiveWindow.WndP roc(Message& m)
at System.Windows. Forms.NativeWin dow.Callback(In tPtr 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();
DataUpdatedEven t (this, new StatusEventArgs (dsRetrievedDat a);
CompareToSecond ary(dsRetrieved Data);
}

<snip>

public delegate void DataUpdated(obj ect sender, StatusEventArgs e);
public event DataUpdated DataUpdatedEven t;

} //End of Verification Class

private DataGrid dataGridVerific ation;
private Verifiy ioVerification;
private Thread ioThread;

private delegate void DataUpdatedDele gate(dsVerifica tion
adsRetrievedDa ta);
private void DataUpdated (dsVerification adsRetrievedDat a)
{
dataGridVerific ation.DataSourc e = adsData.Verific ationData;
}

private void ioVerification_ DataUpdatedEven t(object sender,
StatusEventArg s e)
{
if (this.InvokeReq uired)
{
this.BeginInvok e(new DataUpdatedDele gate(DataUpdate d), new object[]
{e.Data});
return;
}

DataUpdated(e.D ata);
}


Nov 25 '06 #3

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

Similar topics

3
12941
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 looks like not possible to pass more than one. Anybody has a solution? --
2
1565
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
1514
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 is based on the countdown / controlinvoker quickstart at GotDotNet.com. The problems are: (1) There's a memory leak somewhere. I don't know where, but it's
22
25600
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 compile. <WebMethod()> _ Public Function VerifySku(ByVal skus As XmlDataDocument) As DataSet Test program : Dim cartSet As DataSet cartSet = ws.VerifySku(cartSet)
10
15181
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( thesub as <functionptr?> ) dim t as new system.threading.thread( _ new system.threading.threadstart( Addressof thesub )) .... How can I get something like that going in VB.Net?
9
6156
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 unusually long time for the breakpoint to kick in once encountered 2) When it finally does break, I can't step through any code. As soon as I try, the debugger just runs off somewhere and never returns control to me.
19
1595
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" class immediately after the above call, and invoke the above again as soon as the thread starts, it now returns null instead. Can anyone explain this. Thanks.
2
1646
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 for the result of these webservice calls, Each night this code calls some webservices, which return a result I need to store in
1
2534
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 PC and sometimes when i start or restart the PC i have observed that even though the long process is completed splash
0
9325
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9930
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9716
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9716
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9571
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6410
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5180
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3185
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2542
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.