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();
    };
原文地址:https://www.cnblogs.com/yao2yao4/p/3182140.html