dataGridView1.Rows[x1].Cells[y1].Style.BackColor = System.Drawing.Color.Red;
System.Threading.Thread.Sleep(1000);
İ want to wait one second before
Try this function
public void Wait(int time)
{
Thread thread = new Thread(delegate()
{
System.Threading.Thread.Sleep(time);
});
thread.Start();
while (thread.IsAlive)
Application.DoEvents();
}
Call function
Wait(1000); // Wait for 1000ms = 1s
Personally I think Thread.Sleep is a poor implementation. It locks the UI etc. I personally like timer implementations since it waits then fires.
Usage: DelayFactory.DelayAction(500, new Action(() => { this.RunAction(); }));
//Note Forms.Timer and Timer() have similar implementations.
public static void DelayAction(int millisecond, Action action)
{
var timer = new DispatcherTimer();
timer.Tick += delegate
{
action.Invoke();
timer.Stop();
};
timer.Interval = TimeSpan.FromMilliseconds(millisecond);
timer.Start();
}
use dataGridView1.Refresh(); :)
Is it pausing, but you don't see your red color appear in the cell? Try this:
dataGridView1.Rows[x1].Cells[y1].Style.BackColor = System.Drawing.Color.Red;
dataGridView1.Refresh();
System.Threading.Thread.Sleep(1000);