How to prevent windows from freezing?

Possible duplicate:
C # WinForm app - user interface freezes during long run

A C # Windows Forms application created an example run application.

My application works well, but when I tried to move the position of the application or collapse it, it freezes until the process is completed.

Please help: how to prevent my application from freezing?

This is my application code:

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; } } 
+4
source share
2 answers

The reason for its "freeze" is that the processes work in one thread. Move the execution process to another thread using BackgroundWorker.

To prevent copying and pasting, refer to the following links:

+4
source

The only way to prevent this is to delegate the workload to another thread.

There are several classes you can use for this:

A background worker may be the easiest because it provides the means to return the result to the user interface stream. With other parameters, you will need to send the result to the correct stream.

+2
source

All Articles