System.Timers.Timer's SynchronizingObject property
1) What thread will the System.Timers.Timer's Elapsed event run on if I set the timer's SynchronizingObject property to null?
2) Will it run? What's a use case for it, if it does? I mean, in what situation will I want to run a timer on a non-UI thread/worker thread from the thread pool?
Water Cooler v2
February 9th, 2010 3:33pm
Never mind. I think I know the answers to both these questions somewhat.
a) On a worker thread from the thread pool.
b) Will it run? Probably. Will have to try it out and see. But time is a commodity.
Use case: I can think of a few. When I know the operation inside the elapsed event will never use a UI object/control/container, and I want to make the state of the function thread-safe using a lock.
Water Cooler v2
February 9th, 2010 3:46pm
Dude. Just use the clipboard, or the registry.
Seriously - ask Brice.
Aaron
February 9th, 2010 3:50pm
The safe thing is to always assume your current thread is the non-UI thread and marshal over to it via BeginInvoke.
xampl
February 9th, 2010 3:57pm
> The safe thing is to always assume your current thread is the non-UI thread and marshal over to it via BeginInvoke.
Point well-taken. This is esp. handy if I get the timer object from another library. Anyways, its a harmless thing to do in all situations. Nice.
> use the clipboard or registry
WTF??
Water Cooler v2
February 9th, 2010 3:59pm
Heh. That's what SHE said.
SaveTheHubble
February 13th, 2010 11:29am