Click here to Skip to main content
15,891,033 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How I can add delay between execution of two lines means i want to execute one line and then wait for 5 second and then execute second line. thread.sleep is not working well in windows form in c#. Is any other way?

What I have tried:

C#
steps[recursiveStep, left].BackColor = Color.Fuchsia;
                    left++;
                    Thread.Sleep(5000);
                    steps[recursiveStep, left].BackColor = Color.Green;
Posted
Updated 17-Dec-16 11:43am

1 solution

It's complicated, because you are trying to get one thread to do o different things at the same time: show what is going on, and wait for a specific product of time before doing something else - and that isn't going to work.
So set up a Timer, and user that to kick off the second colour change instead of trying to stop the current thread, because of you stop the thread, you can't see any changes...
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900