The differen between Server Timers, Windows Timers, and Thread Timers
2007-01-01 10:19
525 查看
Server-based timers allow you to specify a recurring interval at which an event will be raised in your application. You can then handle this event to provide regular processing. For example, suppose you have a critical server that must be kept running 24 hours a day, seven days a week. You could create a service that uses a timer to periodically check the critical server to ensure that the system is up and running. If the system is not responding, the service can attempt to restart the server or notify an administrator.
There are two types of threads in Win32 architecture: UI threads, and worker threads. UI threads sit idle most of the time and wait for messages to arrive in their message loops. Once they receive a message, they handle it and then wait for the next message to arrive. Alternatively, worker threads are used to perform background processing and do not use message loops. Both the Windows timer and the server-based timer run using an
The Windows timer is designed for a single-threaded environment where UI threads are used to perform processing. The accuracy of Windows timers is limited to 55 milliseconds. These traditional timers require that the user code have a UI message pump available and always operate from the same thread, or marshal the call onto another thread. For a COM component, this would be detrimental to performance.
The server-based timer is designed for use with worker threads in a multi-threaded environment. Because they use a different architecture, server-based timers have the potential to be much more accurate than Windows timers. Server timers can move among threads to handle the raised events.
The thread timer is useful in scenarios where messages are not pumped on the thread. For example, the Windows-based timer relies on operating-system timer support, and if you are not pumping messages on the thread, the event associated with your timer will not occur. The thread timer is more useful in this case.
The Windows timer is located in the System.Windows.Forms namespace, the server timer is located in the System.Timers namespace, and the thread timer is located in the System.Threading namespace.
Note |
---|
The interval for server timers is specified in milliseconds. |
Server Timers, Windows Timers, and Thread Timers
There are three timer controls in Visual Studio and the .NET Framework — the server-based timer you can see on the Components tab of the Toolbox, the standard Windows-based timer you can see on the Windows Forms tab of the Toolbox, and the thread timer that is only available programmatically. The Windows-based timer has existed in Visual Basic since version 1.0, and has remained essentially unchanged. This timer is optimized for use in Windows Forms applications. The server-based timer is an update of the traditional timer that has been optimized to run in a server environment. The thread timer is a simple, lightweight timer that uses callback methods instead of events and is served by thread-pool threads.There are two types of threads in Win32 architecture: UI threads, and worker threads. UI threads sit idle most of the time and wait for messages to arrive in their message loops. Once they receive a message, they handle it and then wait for the next message to arrive. Alternatively, worker threads are used to perform background processing and do not use message loops. Both the Windows timer and the server-based timer run using an
Intervalproperty. The interval of the thread timer is set in the Timer constructor. The timers are designed for different purposes, as evidenced by their handling of threads:
The Windows timer is designed for a single-threaded environment where UI threads are used to perform processing. The accuracy of Windows timers is limited to 55 milliseconds. These traditional timers require that the user code have a UI message pump available and always operate from the same thread, or marshal the call onto another thread. For a COM component, this would be detrimental to performance.
The server-based timer is designed for use with worker threads in a multi-threaded environment. Because they use a different architecture, server-based timers have the potential to be much more accurate than Windows timers. Server timers can move among threads to handle the raised events.
The thread timer is useful in scenarios where messages are not pumped on the thread. For example, the Windows-based timer relies on operating-system timer support, and if you are not pumping messages on the thread, the event associated with your timer will not occur. The thread timer is more useful in this case.
The Windows timer is located in the System.Windows.Forms namespace, the server timer is located in the System.Timers namespace, and the thread timer is located in the System.Threading namespace.
相关文章推荐
- Server Timers, Windows Timers, and Thread Timers的对比
- What’s the difference between <system.web> and <system.webServer>?
- What is the difference between a thread and a process?
- There is a version mismatch between the spring client and the server
- Multi-thread: What is the difference between OpenMP and MPI
- the differences between Server.Transfer and Response.Redirect
- What is the basic difference between NSTimer, NSTask, NSThread and NSRunloop?
- The difference between web container and web server
- 进程与线程的区别 What is the difference between process and thread
- MySQL之——The slave I/O thread stops because master and slave have equal MySQL server UUIDs
- What is the basic difference between NSTimer, NSTask, NSThread and NSRunloop ?
- What's the difference between a thread and a process?
- Levels of integration between the Portal for ArcGIS and the ArcGIS Server
- There is a version mismatch between the spring client and the server
- 20080328 - the difference between a Thread and a Process
- MS SQL错误:SQL Server failed with error code 0xc0000000 to spawn a thread to process a new login or connection. Check the SQL Server error log and the Windows event logs for information about possible related problems
- Multi-thread: What is the difference between OpenMP and MPI
- Fatal error: The slave I/O thread stops because master and slave have equal MySQL server ids;
- 【MySql】The slave I/O thread stops because master and slave have equal MySQL server UUIDs;
- MySQL复制错误 The slave I/O thread stopsbecause master and slave have equal MySQL server UUIDs; these UUIDs must bedifferent for replication to work 解析