Hello gurus Can't find the answer to my question in MSND : Does Timer class guarantees that all handlers subscribed to Elapsed event will be executed on the same threadpool thread ? If yes, will they be executed according the order in wich they were added to Elapsed event ? Thanks
+1
A:
As far as I can see, the only way to ensure that the Elapsed
event handlers are all on the same thread is to set the Timer's SynchronizingObject
property (usually to a control or something on a form, so that the Elapsed event is handled on the UI thread). Otherwise the event is handled on a threadpool thread, meaning it might be the same thread each time but almost certainly won't be.
See: http://msdn.microsoft.com/en-us/library/system.timers.timer.elapsed.aspx
The order of the event handlers firing is probably going to be in the order you add them, but this isn't guaranteed and may change in the future. If your design is dependent upon the events being fired in a particular order, you should change your design.
MusiGenesis
2010-04-13 12:37:14
I think I 've found the answer here : http://msdn.microsoft.com/en-us/library/awbftdfh.aspx •When an event has multiple subscribers, the event handlers are invoked synchronously when an event is raised.Means that handlers are executed on SINGLE threadpool thread one after another.
Alexander.Furer
2010-04-13 13:59:02
@user315454: yes, it means that each time the event is raised, all the subscribing handlers are invoked one after the other on the same thread. However, the next time the event is raised, it's almost certainly on a different thread than the previous time. This is probably mostly semantic at this point, but the Timer class does not guarantee that all handlers will be invoked on the same Thread, since this Thread can and will change from event to event.
MusiGenesis
2010-04-13 14:27:51
However, I don't think you care about that at all. :) You appear to have found the answer to your specific problem.
MusiGenesis
2010-04-13 14:29:19
You are right, my specific problem is "to know that all handlers have finished their processing" PER "TRANSACTION" (raised event).Next problem is to get "choosen thread returned to pool" event :)
Alexander.Furer
2010-04-13 15:00:41