my program locks up on DB queries....

R

Rogelio

hey, I run long queries. like once that take my program about 3 minutes
straight to complete.. like I grab over 100,000 rows, and loop throguh each
row to update a certain value. etc..

the program freezes when all this calculation is going on, so I thought I'd
put a progress bar. I even made it on a separate thread and used the callback
/ delegate stuff to make it show.

so here's how the method goes:


private void btnDoDatabasestuff_Click(object sender, EventArgs e)
{
Thread thProgbar = new Thread(new ParameterizedThreadStart(ShowProgBar));
thProgbar.Start("show");

//Lots of code here to do stuff

Thread thProgbar = new Thread(new ParameterizedThreadStart(ShowProgBar));
thProgbar.Start("hide");
}

the problem is that it STILL locks up. the only difference this time is it
locks up with a progress bar on the screen. it's an animated progress bar and
it still stops moving.

is there any other stuff I should be doing?

thanks.,
 
J

Jon Skeet [C# MVP]

hey, I run long queries. like once that take my program about 3 minutes
straight to complete.. like I grab over 100,000 rows, and loop throguh each
row to update a certain value. etc..

the program freezes when all this calculation is going on, so I thought I'd
put a progress bar. I even made it on a separate thread and used the callback
/ delegate stuff to make it show.

so here's how the method goes:

private void btnDoDatabasestuff_Click(object sender, EventArgs e)
{
Thread thProgbar = new Thread(new ParameterizedThreadStart(ShowProgBar));
thProgbar.Start("show");

//Lots of code here to do stuff

Thread thProgbar = new Thread(new ParameterizedThreadStart(ShowProgBar));
thProgbar.Start("hide");

}

the problem is that it STILL locks up. the only difference this time is it
locks up with a progress bar on the screen. it's an animated progress barand
it still stops moving.

is there any other stuff I should be doing?

It sounds like you're still doing the database stuff in the UI thread,
which is the problem. Have a look at BackgroundWorker, which is
designed for this kind of situation.

Jon
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top