Official Everybody Edits Forums

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.

#1 2016-08-30 21:04:35, last edited by den3107 (2016-08-30 22:10:41)

den3107
Member
From: Netherlands
Joined: 2015-04-24
Posts: 1,025

Would this be a valid way of pausing your code?

Let's start with a notice:

I don't need to know alternatives, they've been spread around the forums enough, I wish to keep this topic to my implementation only to prevent never ending discussions.
READ ABOVE FIRST

Edit2: If you have any questions, try reading the posts below, it already should contain some extra clarity.

Offline

#2 2016-08-30 21:15:35

hummerz5
Member
From: wait I'm not a secret mod huh
Joined: 2015-08-10
Posts: 5,852

Re: Would this be a valid way of pausing your code?

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

Offline

#3 2016-08-30 21:18:33, last edited by den3107 (2016-08-30 21:19:11)

den3107
Member
From: Netherlands
Joined: 2015-04-24
Posts: 1,025

Re: Would this be a valid way of pausing your code?

hummerz5 wrote:

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

#4 2016-08-30 21:39:58, last edited by hummerz5 (2016-08-30 21:49:01)

hummerz5
Member
From: wait I'm not a secret mod huh
Joined: 2015-08-10
Posts: 5,852

Re: Would this be a valid way of pausing your code?

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

#5 2016-08-30 21:55:31, last edited by den3107 (2016-08-30 21:57:58)

den3107
Member
From: Netherlands
Joined: 2015-04-24
Posts: 1,025

Re: Would this be a valid way of pausing your code?

hummerz5 wrote:

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:

hummerz5 wrote:

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

#6 2016-08-30 21:59:23, last edited by hummerz5 (2016-08-30 22:00:01)

hummerz5
Member
From: wait I'm not a secret mod huh
Joined: 2015-08-10
Posts: 5,852

Re: Would this be a valid way of pausing your code?

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

#7 2016-08-30 22:08:37

den3107
Member
From: Netherlands
Joined: 2015-04-24
Posts: 1,025

Re: Would this be a valid way of pausing your code?

hummerz5 wrote:

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

den31071472591317621554

Board footer

Powered by FluxBB

[ Started around 1714930334.4658 - Generated in 0.100 seconds, 11 queries executed - Memory usage: 1.45 MiB (Peak: 1.6 MiB) ]