There are better ways, but here is the simple way that will show you the basics:
private void button1_Click(object sender, EventArgs e)
{
var t = new System.Threading.Thread(new System.Threading.ThreadStart(() =>
{
int i = 0;
while (i < 10)
{
i++;
var ts = new System.Threading.ThreadStart(() =>
{
label1.Text = string.Format("Step is: {0}", i.ToString());
});
if (this.InvokeRequired)
this.Invoke(ts);
else
ts();
System.Threading.Thread.Sleep(1000);
}
}));
t.Start();
}
Basically, you run your code on a different thread than the main thread. This frees the main thread to perform UI updates. Whenever you need to change the UI, you must invoke your code on the main thread.