A background worker is a separate thread from the one that runs the user interface - what that means is that the processor will run it independently (and indeed may run it on a different core if you have more than one). It's a bit like having someone working for you: you can give them a task, and tell them to get on with it, and you don't have to think about it until they have finished.
Simplest code for a separate thread:
private bool run = false;
BackgroundWorker bgw = new BackgroundWorker();
private void myButton_Click(object sender, EventArgs e)
{
if (!run)
{
run = true;
bgw.DoWork += new DoWorkEventHandler(bgw_DoWork);
bgw.RunWorkerAsync();
}
else
{
run = false;
}
}
void bgw_DoWork(object sender, DoWorkEventArgs e)
{
int i = 0;
while (run)
{
Thread.Sleep(1000);
Console.WriteLine("Hello : " + i++);
}
}
The button click sets up a worker, tells it what to do, runs it and buggers off. When you press it again, it kills the thread, by letting it expire naturally.
In your case, the database access code would be in the bgw_DoWork method, and it could report progress if needed via the ProgressChanged Event.
BTW: Don't emulate this directly: multiple presses of the button would cause problems as a new thread would start for each - this is just a simple example.