Problem with methods in a race GUI

This is a discussion on Problem with methods in a race GUI within the C# Programming forums, part of the General Programming Boards category; I am writing a simple program to bet on a race by making simple animations with pictures as the racers. ...

Problem with methods in a race GUI

I am writing a simple program to bet on a race by making simple animations with pictures as the racers. My problem is that I don't know how to make a button_click event wait for a timer_tick event. I would rather make it wait before continuing so the user won't accidentally mess up the racing/betting progress. Here is the code with the problem in it.

Agree with kmdv - the whole idea of event-driven programming is that the individual event handlers should return quickly so that control goes back to the message pump. No event handler should ever pause for any appreciable length of time, and certainly not while waiting for another event, which won't even be able to occur.

On the button click event you could unassign the event handler to the button itself, and have it reassigned in the timer_tick method when IsWinner evaluates as true in that if statement. Only if this is necessary though, otherwise you could just disable the button itself (and of course enable it when the task is finished). What could also be done is that the button is assigned to a different method to indicate that progress is still active if the user tries to click the button a second time before the task completes. Lots of things you could do, but avoid the first suggestion as mentioned by others.

Instead of doing this though, if you're only going to use it once, why keep it in a boolean variable?

Code:

bool IsWinner = mustaches[r].Run();
if (IsWinner)
{

Just do this:

Code:

if (mustaches[r].Run())
{

Because it looks like you're only going to use it once. The only significant part is r, being the incremented numeric value. *NOTE: If this is a readability thing.. Just use a comment to indicate that it means there is a winner, that's what they were invented for.