Question

I created a loadingForm with only a progress bar with marquee style. In my mainForm I'm trying to do this:

//before downloading
loadingForm lf = new loadingForm();
lf.Show();
//start downloading
//finishdownloading
lf.Close();

The loadingForm was shown but the progress bar didn't appear, and the form looked like it was crash. after finishing downloading, the loadingForm was closed and my app continued to run normally. In loadingForm I only have:

void loadingForm_Load(object sender, EventArgs e)
{
     progressbar1.visible = true;
}

I already set progressbar1 style to marquee in loadingForm.design. How do I fix this? thanks for your help in advance.

Was it helpful?

Solution

You should have a look at using BackgroundWorker Class for the time consuming actions, so that the UI can continue showing the progress while the background worker thread does the work.

OTHER TIPS

This is most likely because the download and the form with the progress bar are run on the same thread. You could use a BackgroundWorker to perform the download in a different thread than the form.

The UI thread might not have "resources" to redraw the ui, you should use the background worker as mentioned, or process the application messages in the queue. From the Show() method to the Close() method you should be sure to call Application.DoEvents(), so all windows messages will be processed (along with redrawing messages to your application form)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top