Use of the timer

Source: Internet
Author: User

1.system.timers.timer

(1) Generate recurring events in the application.

(2)If the SynchronizingObject property isnull, the Elapsed event is raised on the ThreadPool thread. If the Elapsed event is processed longer than Interval, this event will be raised again on another ThreadPool thread. in this case, the event handler should be reentrant.

(3)Even if SynchronizingObject is notnull, Elapsed The event can occur after the Dispose or Stop method call, or after the Enabled property is set to false, because the signal that leads to the Elapsed event is always queued for execution thread pool threads. one way to resolve this race condition is to set a flag that notifies the event handler for the Elapsed event that the subsequent event is ignored.

(4)When the Elapsed event is handled by a visual Windows forms component (such as a button), accessing the component through the system thread pool can cause an exception or may not work. to avoid this situation, you can set SynchronizingObject as a Windows forms component that will cause the method that handles the Elapsed event to be called on the same thread that created it.

2.System. Thread.timer

(1) The callback method executed by the timer should be reentrant because it is called on the ThreadPool thread.

(2) When you create a timer, you can specify the amount of time to wait before the first execution of the method (the cutoff time) and the amount of time to wait after the execution period (time period).

(3) SynchronizingObject is not supported.

3.system.windows.form.timer

(1) implements a timer that raises events on a user-defined interval. This timer is best used in Windows Forms applications and must be used in Windows.

Use of the timer

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.