Buttons do not refresh until end of game, How to fix

ALT

Member
Joined
Feb 23, 2006
Messages
9
Programming Experience
10+
As I am a first time poster allow me to give you some information:
I have been developing for hire since 1982, but have only seriously working with .Net for a few months, and only half that time with VB.Net. The project that I am now working on is a ‘super’ tick-tack-toe game. (Heck I had to start somewhere:) ) Anyhow one of the modes the game can work in is all computer players.

I want to see the first computer player’s move, then the next players move etc. I have a SLEEP call to slow the plays down so that us mere humans cane watch the exciting action. ;)

What is happening is that there is no refreshing of the button’s text value ( X or O ) or background color ( The winning 3 in a row should be a lovely purple color ) until the game is over then the final ‘result’ is flashed on screen, then pop!

So folks I’ve tried a number of unsuccessful coding ideas, what is the magic that I need to have the form/buttons refresh right after I make a change to them?
 
If you Sleep the thread then NOTHING can happen, then when the thread wakes up it just gets on with making the next move and doesn't bother to refresh the form. You should call Refresh on the form before calling Sleep. Also, I'd probably not use Sleep at all because, as I said, nothing can happen while the thread is sleeping. Why not just use a Timer and make a move on each Tick? That way the UI will remain responsive the whole time.
 
Thanks for the suggestions ( I have been away from the project for a while, hence my delay in the response). The key for me was calling the form's refresh method. I was calling invalidate ( what an odd method name ) etc., but missed the simple refresh.

Thanks again
Anthony
 
Calling Invalidate would normally be OK, because the response to an invalidated control is to redraw it. Your problem was that you weren't allowing time for the redraw to occur. By calling Refresh you are explicitly redrawing the form instead of implicitly via Invalidate.
 
Back
Top