First, you don't need the variable f - you'll see why in a moment.
Second, your
BackgroundWorker
object should support cancellation so that it cleans up correctly if the user does something to dismiss the form while the worker is busy.
The while statement should look something like this:
private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
{
BackgroundWorker worker = sender as BackgroundWorker;
while(!worker.CancellationPending)
{
}
}
Third,
ALL UI updates should be performed through delegates (using
Invoke
). You may need more than one depending on what you want to accomplish.
Lastly, the name "Invoke" is a poor choice for your button control, especially since there is an
Invoke()
method. Change it to
buttonInvoke
, or something like that.