Technically, you don't have to create a new thread. Instead, you can call Application.DoEvents() to force window messages (mouse clicks, key presses, and so on) to be processed. That would go something like this:
public partial class Form1 : Form
{
bool closing = false;
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
for (int i = 0; i < 100; i++)
{
if (closing) break;
progressBar1.Value = i;
System.Threading.Thread.Sleep(100);
Application.DoEvents();
}
if (!closing) MessageBox.Show("Done!");
}
private void button2_Click(object sender, EventArgs e)
{
MessageBox.Show("Did it");
}
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
closing = true;
}
}
However, I would recommend you learn how to use threads instead.