I am making a game wumpus world in winforms in which an agent(computer) can move in 4 directions. I am using button control for base and showing and hiding images where ever needed. i used Thread.Sleep for that but problem is that when i click button nothing is showing on form. the process on background is working fine but it is not showing each step. and yes i am using Thread.Sleep
in current UI
Thread.
I want to show every step to users with interval of 2 seconds.

- 2,948
- 2
- 23
- 47
-
You are using `Thread.Sleep` on the current UI thread? – gunr2171 Jul 21 '13 at 14:07
2 Answers
it's hard to answer without any code to go by, but the main problem as i understand it is that you change the look of the world, and then tell it to sleep, witch means nothing will be painted. and then when the thread wakes up, you again change the world and make it sleep. nothing will be painted that way.
better way to do it will be timer, make it a single timer and a queue of events that needed to be shown and you are on your way to do it.
are you working on winForms, because if you are working on WPF you can do much nicer things
Edit: I'm not saying that Timer is the best way to do it, but it's a good valid way

- 11,411
- 10
- 42
- 70
Using Thread.Sleep is a poor design choice for several reasons:
- It blocks the thread for the duration of the time it is sleeping.
- It uses up threads in the thread pool, so this solution will not scale well at all.
- It is a bad timing mechanism, because there is a time slice, or quantum, in play here that varies between operating systems and even versions of the same operating system (read: Windows).
This previous SO question gives more information about why Thread.Sleep is bad:

- 1
- 1

- 34,606
- 12
- 65
- 80