Comparison of Server Timers, Windows Timers, And Thread Timers

xiaoxiao2021-03-06  108

Server Timers provides a mechanism for performing regular operations, such as: There is a key service that requires 7 * 24HOURS / WEEK, then you can create check programs using Timer, Timed Check This key service is started, if not start, check The program restarts the key service and informs the system administrator

Note: The minimum unit of SERVER TIMERS is Haixi

Server Timers, Windows Timers, and Thread Timers

There are three Timers, Server-based Timer in the DOTNET Framework in Toolbox's Components Tab, the standard Windows-Base Timer in Toolbox's Windows Forms Tab, and Thread Timer can only be used in the program (no UI interface), Windows- Base Timers exists from VB1.0, and the essence has not changed. Windows-base timer is usually used in WinForm. Servers-base Times is a traditional TIMERS upgrade, optimization, more applicable to the Server environment, Thread Timers is a simple Lightweight Timer, just replacing the Event, for Threadpool's Threads service.

Threads There are two architectures in Win32 program: UI Threads, Worker Threads, ui threads is waiting for new Message to Message Loops, once there is new Message, they are Handle New Message, and wait for the next Message, the opposite, Worker Threads Perform a background operation without Message Loops.

Both Windows Times and Server Timer use the Interval property, which is set in Timer's Constructor, and Timers sets this property for different design purposes.

Windows Timers is designed for Single-Threaded, requiring users to write UI interfaces to activate it, and since the beginning in a thread, or Marshal a call to another Thread, this is harmful to COM components Server Timers is designed for Multi-Threaded, which should have different architectures, more usage time, Server can boast Thread Thread Timers without Message is very effective, such as Window Timer relying on OS support, if not Message In Thread, the events in Timers will not trigger, and at this time, Thread Timer is useful.

Windows Timers In the namespace of System.Windows.Forms, Server Timer In System.Timers' namespace, Thread Timer's key elements of Server Timer in System.Threading's namespace will generate Timer.Elapsed, you can take it , Implement other important attributes and methods of other operations

Interval is a scan time interval (in milliseconds), triggered EVENT events. For example: INTERVAL is 1000, it is to perform an AutoreSet detection every other second after Event trigger, True, continue, false is stopped The start method sets the Timers 'enabled attribute to true (allowing Timers to start) if Timer has start, then reset the Timer Stop method Set the Timers' enabled property to True (Timers Stop) Sample Code: Private Void CreateTimer () {System. Timers.Timer Timer1 = new System.Timers.Timer (); Timer1.Enabled = true; Timer1.Interval = 5000; Timer1.Elapsed = new System.Timers.ElapsedEventHandler (Timer1_Elapsed);} private void Timer1_Elapsed (object sender, System .Timers.estapsedeventargs e) {system.windows.Forms.MessageBox.show ("Elapsed!", "Timer Event Raised!");

转载请注明原文地址:https://www.9cbs.com/read-100413.html

New Post(0)