I use C#'s BackgroundWorker object frequently to start a thread and perform a task. What's the easiest way to accomplish the same thing in Delphi?
Here's some code in C#:
private void button1_Click(object sender, EventArgs e)
{
BackgroundWorker bg = new BackgroundWorker();
bg.DoWork += new DoWorkEventHandler(bg_DoWork);
bg.RunWorkerCompleted += new RunWorkerCompletedEventHandler(bg_RunWorkerCompleted);
test_number++;
object[] arguments = { "test", test_number };
bg.RunWorkerAsync(arguments);
}
void bg_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
{
// done.
}
void bg_DoWork(object sender, DoWorkEventArgs e)
{
// do actual work here
}