Wait one second in running program

前端 未结 10 1222
暗喜
暗喜 2020-12-08 12:30
dataGridView1.Rows[x1].Cells[y1].Style.BackColor = System.Drawing.Color.Red;
System.Threading.Thread.Sleep(1000);

İ want to wait one second before

10条回答
  •  没有蜡笔的小新
    2020-12-08 13:04

    Busy waiting won't be a severe drawback if it is short. In my case there was the need to give visual feedback to the user by flashing a control (it is a chart control that can be copied to clipboard, which changes its background for some milliseconds). It works fine this way:

    using System.Threading;
    ...
    Clipboard.SetImage(bm);   // some code
    distribution_chart.BackColor = Color.Gray;
    Application.DoEvents();   // ensure repaint, may be not needed
    Thread.Sleep(50);
    distribution_chart.BackColor = Color.OldLace;
    ....
    

提交回复
热议问题