In my case I’ve got a game server, with the CLR threadpool handling the sockets, and a managed threadpool for the other stuff. I’m trying to figure out what the best way to handle events like, an npc casting a spell, or despawning after a set period is.
I could just write some sort of Timer wrapper that gets a new (managed)threadpool thread for each action I want to perform, like new TimedEvent(1500, npc.Cast(Spells.FireBall)); and have it check against the system time, but, I think, with multiple timers like that running, each individually checking the elapsed time is inefficient.
Would some sort of dispatcher thread be better?
Thanks in advance.
Have a look at how UOX3 does that in case you don’t know that server app. It’s a .Net/C# Ultima Online server.
And to your concrete question. It depends on how many events you expect. If you expect thousands per second going the timer/thread way is likely to not really work well.