DataObjectFactory fails when using multiple threads

This forum is for programmers who have questions about the source code.
Post Reply
User avatar
jordansparks
Site Admin
Posts: 5744
Joined: Sun Jun 17, 2007 3:59 pm
Location: Salem, Oregon
Contact:

DataObjectFactory fails when using multiple threads

Post by jordansparks » Wed Jul 30, 2008 7:47 am

This message is intended mostly for Frederik Carlier.

I'm adding some code that does some database intensive routines in a separate thread. Namely, it grabs all 6000 patients from the database in about 1 second and starts uploading them to an external server. But that fails when using this:
command="SELECT * FROM patient";
DataObjectFactory<Patient>.CreateObjects(command);

I didn't have to follow it far to find the failure. Inside CreateObjects(command), it calls CreateObjects(reader). When it starts in on
while (reader.Read()) {
values.Add(CreateObject(reader));
}
It reads successfully at least once, and then at some point it stops. It doesn't give any error message, it just closes the thread I think. So it never makes it past that loop.

Now, when I this:
General.GetTable(command);
instead of the DataObjectFactory, then it works just fine. I get all 6000 patients returned just like I want.

So I have a solution for my immediate problem, but I'm worried about long-term problems since I don't really understand why it failed. I would like to use background threads eventually for some database operations, and I don't want any surprises. Anyone have any ideas what's going on?
Jordan Sparks, DMD
http://www.opendental.com

jweek
Posts: 4
Joined: Sun Jun 01, 2008 2:34 pm

Re: DataObjectFactory fails when using multiple threads

Post by jweek » Tue Aug 05, 2008 5:04 pm

Would it be possible to supply the example code, which uses the DataObjectFactory? I'm assuming that using the DataObjectFactory works when not executing in a separate thread?

User avatar
jordansparks
Site Admin
Posts: 5744
Joined: Sun Jun 17, 2007 3:59 pm
Location: Salem, Oregon
Contact:

Re: DataObjectFactory fails when using multiple threads

Post by jordansparks » Tue Aug 05, 2008 9:06 pm

It's in the code in the head, FormUAppoint.cs, line 582. The way it is now, a few lines later, in Patients.cs, line 68, it uses
DataTable table=General.GetTable(command);
because
DataObjectFactory<Patient>.CreateObjects(command);
was failing.

I'm really not too concerned about it. Just mildly interested.
Jordan Sparks, DMD
http://www.opendental.com

Post Reply