void WorkerDoWork(object sender, DoWorkEventArgs e) { var worker = sender as BackgroundWorker; var aionProcessKiller = new AionProcessKiller(Log, AionBuildProcess); for (var i = 0; i < BuildTimeOutInSeconds; i++) { if (worker.CancellationPending) { e.Cancel = true; break; } Thread.Sleep(1000); } if (!e.Cancel) { aionProcessKiller.Kill(); } }