System Timers Question

08/12/2013 17:55 hacksaw#1
When using system timers for say inside an event that runs once per day, Should you always call Timer.Dispose() for each timer after the event ends and you have stopped the timers?
08/12/2013 18:38 InfamousNoone#2
There's more than one "Timer" class in .NET, which are you referring to?
08/12/2013 18:58 hacksaw#3
System.Timers.Timer
08/12/2013 23:09 Super Aids#4
No. You shouldn't use it at all.
08/12/2013 23:44 hadeset#5
An event, that runs once a day? I don't think using a Timer for this occasion is very advisable. I don't know which source kids be using these days, but I'm sure it has a thread somewhere that checks events by DateTime stamps whether they should be called or not on each step. Perhaps that is the place, you should implement that daily event.

However, if you must use a Timer, you can call Dispose if you want. It should not matter that much, because the GarbageCollector should automatically dispose of it anyways, once it has lived its use, or am I wrong? (I imagine Timer's finalizer calls Dispose)
08/13/2013 00:13 ChingChong23#6
make your own timer on an existing thread.
08/13/2013 00:20 hacksaw#7
Im using Impluses Base 5165 Source, I have been using Timers in daily events and also for certain Player Quests where things are triggered at certain points or have time limits in them, I mainly started using them so everything was kept tidy and all stuff for each individual thing in 1 place for each given event or quest, There is a Thread that keeps check time wise for things like Buffs ect ect. Would there be any advantage to doing away with the timers and moving the timing part into the Thread mentioned above?

And the reason i asked about dispose was just i had someone looking over some code and when they saw Timer.Stop() said you should also use Timer.Dispose() after it, Which i havent been doing so i was just wondering again if that was the correct way to do it or if he was wrong.
08/13/2013 12:31 hadeset#8
Quote:
Originally Posted by hacksaw View Post
Im using Impluses Base 5165 Source, I have been using Timers in daily events and also for certain Player Quests where things are triggered at certain points or have time limits in them, I mainly started using them so everything was kept tidy and all stuff for each individual thing in 1 place for each given event or quest, There is a Thread that keeps check time wise for things like Buffs ect ect. Would there be any advantage to doing away with the timers and moving the timing part into the Thread mentioned above?

And the reason i asked about dispose was just i had someone looking over some code and when they saw Timer.Stop() said you should also use Timer.Dispose() after it, Which i havent been doing so i was just wondering again if that was the correct way to do it or if he was wrong.
Like I said, it couldn't hurt to call Dispose yourself, but you don't have to either, because of GarbageCollector, that .Net has.
08/13/2013 12:49 Super Aids#9
hadeset, the GC is not instantly removing unused memory :)
08/13/2013 12:53 hadeset#10
Quote:
Originally Posted by Super Aids View Post
hadeset, the GC is not instantly removing unused memory :)
Yeah, but at some point, it does it anyways. Well not removing memory, but calling finalizers, which are supposed to do the memory freeing.
08/13/2013 13:18 ChingChong23#11
i am surprised a lot of these servers don't run into concurrency issues, throwing tasks on random threads like that, unless they do!
08/13/2013 13:38 hadeset#12
Quote:
Originally Posted by ChingChong23 View Post
i am surprised a lot of these servers don't run into concurrency issues, throwing tasks on random threads like that, unless they do!
They probably do. :O
08/13/2013 13:47 Super Aids#13
Quote:
Originally Posted by hadeset View Post
Yeah, but at some point, it does it anyways. Well not removing memory, but calling finalizers, which are supposed to do the memory freeing.
You're better off doing it yourself at some points. Not saying it's necessary in this case, but with streams and such it's highly recommended.

Quote:
Originally Posted by ChingChong23 View Post
i am surprised a lot of these servers don't run into concurrency issues, throwing tasks on random threads like that, unless they do!
Ikr? Well if I am correct Impulse source had a lot of deadlock problems as well.
08/19/2013 23:41 -impulse-#14
Quote:
Originally Posted by Super Aids View Post
You're better off doing it yourself at some points. Not saying it's necessary in this case, but with streams and such it's highly recommended.



Ikr? Well if I am correct Impulse source had a lot of deadlock problems as well.
Deadlocks hardly. Race conditions, not really either. The source I released used one thread per client so they would be fairly rare. Though, a very well known problem would be the collection modified exceptions which is a result of a lack of locks which do exists in most sources.
08/20/2013 00:26 Super Aids#15
One thread per client is exactly when it happens and @ the collections [Only registered and activated users can see links. Click Here To Register...]