如何防止窗体“挂起”?

use*_*034 5 c# freeze winforms

可能的重复:
C# WinForm 应用程序 - UI 在长时间运行期间挂起

我在 C# Windows 窗体中创建了一个进度条示例应用程序。

我的应用程序运行良好,但是当我尝试移动应用程序位置或最小化时,它会“挂起”,直到它的进程不符合要求。

请帮助:如何防止我的应用程序“挂起”?

这是我的应用程序代码:

public partial class ProgressBar : Form
{
    public ProgressBar()
    {
        InitializeComponent();
    }

    private void button1_Click(object sender, EventArgs e)
    {
        int value;
        for (value = 0; value != 10000000; value++)
            progressBar1.Value = progressBar1.Value + 1;

        MessageBox.Show("ProgressBar Full", "Done", 
                        MessageBoxButtons.OK, MessageBoxIcon.Information);
        this.Close();
    }

    private void ProgressBar_Load(object sender, EventArgs e)
    {
        progressBar1.Maximum = 10000000;
    }
}
Run Code Online (Sandbox Code Playgroud)

The*_*kZn 4

它“挂起”的原因是因为进程在同一个线程中运行。使用BackgroundWorker 将进度条进程移动到另一个线程。

要防止复制+粘贴,请参阅以下链接: