Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

I am developing an application that has two tables in a Dataset and uses threads to populate them with data. The two tables have a relationship and all the table�s columns are already defined. The first table has several columns databound to TextBoxs and the second table is bound to a datagrid. The first table is list of customers called �AR0024�, and the second is called �AR0032�. The first table�s primary key is �IDCUST�.

 

First the application fills just the first table�s IDCUST column using an ODBCDataAdapter. When the current record is changed the application fills in the rest of the data in the row using a command like;

 

Ds.Tables(�AR0024�).Rows.Find(IDCUST)(ColName) = Value

 

Where the IDCUST var is determined by reading the first column and the ColName and Value are drawn from a proprietary accounting application. All of this is executed in a thread and works just fine.

 

The second table is filled using another thread and is populated entirely using the proprietary accounting application. The thread goes something like this;

 

Dim dr as datarow

Do While (there�s still records to retrieve from the proprietary app)

Dr = ds.Tables(�AR0032�).NewRow

For I = 0 to (Propitary Column Count) - 1

(Fills in dr from Proprietary application)

Next

Ds.tables(�AR0032�).rows.add(dr)

(Command to get Next Record From Proprietary Application)

Loop

 

When the datagrid that the table AR0032 is bound to is visible, sometimes I get a null reference exception and sometimes the application just shuts down without firing an exception. I know this has something to do with the threading, but it needs to be done without the application waiting for it to finish.

 

I�ve tried using delegates to pass data back and forth, but it makes no difference.

 

Any ideas?

  • *Experts*
Posted

If you're trying to find the exception, turn on the catching of all exceptions.

(This is from memory):

Select Debug->Exceptions

Find the ".NET Runtime..." node in the treeview (second down in my list of four items).

 

There should be some radio buttons in a few groups at the bottom. The top group should have something like "Enable" or "Break...".

 

Sheesh, you'd think I'd have this memorized... if you can't find it like this, let me know. This should stop on all .NET exceptions, even if it's in an assembly that you don't have sourcecode to (I've gotten exceptions in System.Data a LOT).

 

In C# Express (I have beta 1, I think), you can use:

Debug->Exceptions->Break When an Exception Is Thrown

 

The default behavior of Visual Studio is to not break if an exception is caught. The options above will allow breaking on any exceptions.

 

Another thing to check is what threads are running (another Debug->Other Window kinda toolbar). You might be able to set breakpoints up that way, too.

 

I'm not sure why filling a dataset needs to be so... complicated? But if you really need multiple threads to fill it, better make sure the "base logic" of when each table will get filled is in sync. You probably know that already, but if you have any doubts about the code, I'd run some tests to flesh out any other bugs first.

 

-ner

"I want to stand as close to the edge as I can without going over. Out on the edge you see all the kinds of things you can't see from the center." - Kurt Vonnegut

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...