tags:

views:

171

answers:

1

I wold like to create a progressbar for my application, im running i got one main form that opens a Child form with a datagrid with a loop i<30. the loop takes a bit of time as it querys the database.

this hold up looks to the user like the software is stuck, so i was thinking of creating a progressbar to show how long the operation is in the loop.

what is needed how do i start solving this problem?

form1 = Main form Child1 = datagrid form Child2 = Progressbar form

i was thinking on letting the main form hold a int variable poX = 0 and the child1 do in the loop

for (int i, i < 30, i++)
{
   //code for query
   form1.posX = form1.posX++
}

then let Child2 use the poX to progress the bar. But is this the correct path? and how do i pass values from the children to the main form and back?

+2  A: 

What you need to do is use a different thread to perform your lengthy operation while updating the progress bar. This wont freeze your UI thread. Take a look into BackgroundWorker class and How To Use BackgroundWorker

Stan R.