Game Development Stack Exchange is a question and answer site for professional and independent game developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I want to find out the best way of creating time based events in games. Lets talk for example about Texas Holdem Poker. Server can handle thousands of tables and in every table we have timers: turn timer, hold seat timer and so on.

What is the best way of timers realization for this purpose?

Is System.Timers.Timer class can handle this or it will be more reasonable to create a separate thread with sorted time queue (for example an ascending sorted list with int values which represent time in ms remained)?

Thanks in advance, Valentin

share|improve this question
up vote 4 down vote accepted

Timer can handle it, your main concern will be memory usage with thousands of requests.

A suggestion is to create an Async timer with a callback to signal the table or player of an action. The function signature is this :

Timer( TimerCallback callback, object state, uint dueTime, uint period)

so instead of keeping track of the timer queue yourself and having some heavy logic, you can just add a timer with a callback to your logic, and pass th

void HandleAction (object state)
         //Do the work here

      static void CreateTimer( )
         Program p = new Program(); 

         Timer myTimer = new Timer
            (p.HandleAction, //method
               "Parameter to pass to the function.", //parameter
               2000,   // execute this after 2 seconds
               1000);  // Repeat every second 
share|improve this answer

This is how I'd do it, in general programming (not just C#)

I'd have a thread to handle my timers, with an ordered queue with datetime values for all future events.

Your timer thread would look like this:

while (true)
    curr_date = time();
    while ( < curr_date)
        act(; // usually very simple stuff, like alerting another thread
    thread.sleep( - curr_date);

In addition, any thread who wants to add a message into your timer list, should call a function like this:


Would something like this solve your problem?

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.