Forum C# Can't stop Timer

Can't stop Timer

Postby n0uk » September 20th, 2010, 11:06 am

Hi.

I develop a multiplayer strategy game based on playerio service. And have one problem - i can't stop Timer objects.
That's sample of the code:

> this._generateInterval = GameCode.AddTimer(callback, this._generateTimeout);
In another place i call
> this._generateInterval.Stop();
> // speed up
> this._generateInterval = GameCode.AddTimer(callback, this._generateTimeout / 2);

And getting the two working timer instances. Timer don't stop. Where could be the problem?
I have .NET Framework 3.5 and last version of playerio library.

Sorry for my bad English.
n0uk
 
Posts: 1
Joined: September 12th, 2010, 6:53 pm

Re: Can't stop Timer

Postby Oliver » September 21st, 2010, 1:18 pm

Hey,

I just did a quick test with the latest Development Package, and the timers work and are stoppable with the .Stop() method.

My guess is that you accidentally overwrite the _generateInterval property with a new timer, so you don't have a reference to the old timer...

Best,
Oliver

Here is the test code i used:

Code: Select all
namespace MyGame {
   public class Player : BasePlayer {
      public string Name;
   }

   public class GameCode : Game<Player> {
      private Timer timer;

      // This method is called when an instance of your the game is created
      public override void GameStarted() {
         // This is how you setup a timer
         this.timer = AddTimer(delegate {
            Console.WriteLine("timer ping");
         }, 500);
      }

      [DebugAction("Stop", DebugAction.Icon.Stop)]
      public void PlayNow() {
         timer.Stop();
      }

   }
}
User avatar
Oliver
.IO
 
Posts: 1159
Joined: January 12th, 2010, 8:29 am

Re: Can't stop Timer

Postby katopz » September 30th, 2010, 5:51 am

sry, i got noob question on server side

if i didn't stop timer, it will run forever after 1st call until the world end or server restart?
which mean i can you this behavior to run some script forever?

if it possible, so can i do this?
because i think this can melt down server easily, so i should asking first :oops:
katopz
 
Posts: 3
Joined: September 28th, 2010, 6:12 am

Re: Can't stop Timer

Postby default0 » September 30th, 2010, 10:09 am

katopz wrote:sry, i got noob question on server side

if i didn't stop timer, it will run forever after 1st call until the world end or server restart?
which mean i can you this behavior to run some script forever?

if it possible, so can i do this?
because i think this can melt down server easily, so i should asking first :oops:


Yo!

Yeah, the timer runs forever if you dont stop it in your code.
Also, the server are not going to melt by your timer, they are able to handle it.
Just DO NOT set a timer at a low frequency and send messages in the code it executes each time or your bandwidth usage will be doomed.

Best regards
Try to play my Game: -->BlackGalaxy<--
User avatar
default0
 
Posts: 115
Joined: February 2nd, 2010, 6:46 pm
Location: Germany

Re: Can't stop Timer

Postby Oliver » October 1st, 2010, 1:22 pm

Your timers will run as long as the room is open (there are players in it).

When the last person leaves the room, the room is closed and all timers are terminated.

Best,
Oliver
User avatar
Oliver
.IO
 
Posts: 1159
Joined: January 12th, 2010, 8:29 am

Re: Can't stop Timer

Postby katopz » October 1st, 2010, 1:51 pm

Hey Oliver

Your timers will run as long as the room is open (there are players in it).
When the last person leaves the room, the room is closed and all timers are terminated.


is this happen automatic? i refer to c# server side base code and i didn't see any stop timer related there?
or do i've to check this my self when each player leave room and player num is zero then stop it?

i start thinking that this behavior should doc somewhere? maybe i just miss it

thanks for answer :)
katopz
 
Posts: 3
Joined: September 28th, 2010, 6:12 am

Re: Can't stop Timer

Postby Oliver » October 1st, 2010, 1:53 pm

This happens automatically!

- Oliver
User avatar
Oliver
.IO
 
Posts: 1159
Joined: January 12th, 2010, 8:29 am


Return to C#