It's not the end of the Internet, but you can see it from here.

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?
Permalink Send private email 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.
Permalink Send private email Water Cooler v2 
February 9th, 2010 3:46pm
Dude.  Just use the clipboard, or the registry.

Seriously - ask Brice.
Permalink 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.
Permalink Send private email 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??
Permalink Send private email Water Cooler v2 
February 9th, 2010 3:59pm
Heh.  That's what SHE said.
Permalink SaveTheHubble 
February 13th, 2010 11:29am

This topic is archived. No further replies will be accepted.

Other topics: February, 2010 Other topics: February, 2010 Recent topics Recent topics