private void cmdNewSearch_Click(object sender, EventArgs e) { AsyncTestQuery search = new AsyncTestQuery(); if (search.ShowDialog() == DialogResult.OK) { // Start the new search. EratosthenesTask worker = new EratosthenesTask(search.From, search.To); worker.Completed += new FindPrimesCompletedEventHandler(WorkerCompleted); lock (workers) { workers.Add(worker); statusPanel.Text = String.Format("Currently running {0} tasks.", workers.Count); } worker.Start(); } search.Dispose(); }