BackgroundWorker
Constants.Worker = new BackgroundWorker(); Constants.Worker.WorkerSupportsCancellation = true; Constants.Worker.DoWork += delegate { while (!Constants.Worker.CancellationPending) { Thread.Sleep(1000); for (int i = 0; i < ProgramStatus.ChannelCount; i++) { if (ProgramStatus.IsStopped[i]) { pictureBoxs[i].Image = pictureBoxs[i].ErrorImage; } } } }; Constants.Worker.RunWorkerAsync();
Closing += delegate { Constants.Worker.CancelAsync(); };