Am Writing A Program That Calculates The Distance Moved By An Object In Meters. Am Using Milliseconds To Calculate The Distance. The Problem Is That The Timer Slows When I Include The Code For Inserting The Distance, Road Signs And Speed Limit Into A Table Using SQL. What Could Be The Problem?
if
(ITime_2 > 0)
MouseInfo
答案 0 :(得分:0)
Timers are not guaranteed to execute exactly when the time interval occurs, but they are guaranteed to not execute before the time interval occurs. This is because DispatcherTimer operations are placed on the Dispatcher queue like other operations. When the DispatcherTimer operation executes is dependent on the other jobs in the queue and their priorities.
If a System.Timers.Timer is used in a WPF application, it is worth noting that the System.Timers.Timer runs on a different thread then the user interface (UI) thread. In order to access objects on the UI thread, it is necessary to post the operation onto the Dispatcher of the UI thread using Invoke or BeginInvoke. Reasons for using a DispatcherTimer opposed to a System.Timers.Timer are that the DispatcherTimer runs on the same thread as the Dispatcher and a DispatcherPriority can be set on the DispatcherTimer.
i.e. Your DispatcherTimer and your DB access code are both running on the same thread and so are not asynchronous.