Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All

Timer::SynchronizingObject Property

Gets or sets the object used to marshal event-handler calls that are issued when an interval has elapsed.

Namespace:  System.Timers
Assembly:  System (in System.dll)

[BrowsableAttribute(false)]
[TimersDescriptionAttribute(L"TimerSynchronizingObject")]
public:
property ISynchronizeInvoke^ SynchronizingObject {
	ISynchronizeInvoke^ get ();
	void set (ISynchronizeInvoke^ value);
}

Property Value

Type: System.ComponentModel::ISynchronizeInvoke
The ISynchronizeInvoke representing the object used to marshal the event-handler calls that are issued when an interval has elapsed. The default is nullptr.

When SynchronizingObject is nullptr, the method that handles the Elapsed event is called on a thread from the system-thread pool. For more information on system-thread pools, see ThreadPool.

When the Elapsed event is handled by a visual Windows Forms component, such as a button, accessing the component through the system-thread pool might result in an exception or just might not work. Avoid this effect by setting SynchronizingObject to a Windows Forms component, which causes the method that handles the Elapsed event to be called on the same thread that the component was created on.

NoteNote

Even if the SynchronizingObject property is not nullptr, Elapsed events can occur after the Dispose or Stop method has been called or after the Enabled property has been set to false, because the signal to raise the Elapsed event is always queued for execution on a thread pool thread. One way to resolve this race condition is to set a flag that tells the event handler for the Elapsed event to ignore subsequent events.

If the Timer is used inside Visual Studio in a Windows Forms designer, SynchronizingObject is automatically set to the control that contains the Timer. For example, if you place a Timer on a designer for Form1 (which inherits from Form), the SynchronizingObject property of Timer is set to the instance of Form1.

.NET Framework

Supported in: 4, 3.5, 3.0, 2.0, 1.1, 1.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Community Additions

ADD
Show:
© 2015 Microsoft