Do you think I could just leave this part blank and it'd be okay? We're just going to replace the whole thing with a header image anyway, right?
You are not logged in.
Let's start with a notice:
Edit2: If you have any questions, try reading the posts below, it already should contain some extra clarity.
Offline
Offline
Did you explain why you have autoResetEvent? It seems extra to me. Perhaps if it was public then external code would interface with it nicely?
Or internal, I guess. Maybe I'll give it a google
The autoresetevent is there to "lock the code", until it's Set() method has been called.
Without it you'd just start a timer and right after call ProcessWinner(), without any delay.
Offline
edit: wait, you didn't want other answers.
In this post I would tell you what I think is closer to the right answer. I cannot say that your method is completely wrong as I don't understand the implications of thread-hogging.
edit2: My last revision still hinted at other possibilities.
Offline
What if we just assigned ProcessWinner to an event handler like Tick? I thought the gist of setting up a Timer was to avoid having to hog a thread like we are.
edit: yeah the loop would have to go as well... the timer is supposed to take care of that stuff
The hogging is actually meant to happen, forgot to mention the GameMaster class would run in a separate thread.
The while loop it to keep starting up a new round, normally "true" would be replaced by an expression to see if the next game would have to start (imagine an elimination game where a game consists of rounds where each round a couple players would be eliminated).
The timer just takes care of waiting a certain amount of time, while allowing for other possibilities a simple Thread.Sleep() wouldn't have.
Again, as said in the edit, usually there's much more to process than just the ProcessWinner() method, where a lot of variables are used, which would need an unnecessary big scope to process everything in the timer elapsed event (and would bring other problems, if not watched out for).
EDIT:
edit: wait, you didn't want other answers.
What you gave was an adjustment/repair suggestion/however you want to call it, which is different from a complete alternative. Aside from that you also tried to get clarity from the OP.
Offline
OK, that makes more sense. I'm still not sure about your idea, but that's OK. Just want to say that your while condition wouldn't tick save for every five minutes. So, it'd be more of a "Should we stop running rounds now" instead of a "Should this round stop" but perhaps you already know that
counter-edit: yeah, I edited out that part where I said "boo on you this is magic here" so I mean thanks
Offline
OK, that makes more sense. I'm still not sure about your idea, but that's OK. Just want to say that your while condition wouldn't tick save for every five minutes. So, it'd be more of a "Should we stop running rounds now" instead of a "Should this round stop" but perhaps you already know that
As said in the casus (the imagine stuff), after the initialization (when the round starts) the round goes on for 5 minutes before determining the winner, it's not that each while tick would have to be exact 5 minutes.
For simplicity of the example I also just made it a while true, while, obviously, you'd normally check somewhere if you should stop starting new rounds.
Again: The given code isn't for an actual BAL idea, it's just an example to show the waiting mechanic.
Which consists of the timer (measure time) and the autoresetevent (lock thread and unlock once timer done).
P.S. Am off to sleep now, so won't reply for a couple hours if more questions pop up.
Offline
[ Started around 1732412433.403 - Generated in 0.050 seconds, 10 queries executed - Memory usage: 1.45 MiB (Peak: 1.6 MiB) ]