3

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.

4

3 回答 3

3

您应该查看使用BackgroundWorker 类来执行耗时的操作,以便 UI 可以在后台工作线程执行工作时继续显示进度。

于 2010-12-21T13:13:16.033 回答
1

这很可能是因为下载和带有进度条的表单在同一个线程上运行。您可以使用BackgroundWorker在与表单不同的线程中执行下载。

于 2010-12-21T13:12:52.383 回答
0

UI 线程可能没有“资源”来重绘 ui,您应该使用前面提到的后台工作程序,或者处理队列中的应用程序消息。从 Show() 方法到 Close() 方法,您应该确保调用 Application.DoEvents(),以便处理所有 Windows 消息(以及将消息重绘到您的应用程序表单)

于 2010-12-21T13:27:26.463 回答