-2

I'd like to know is there any other option to show current time without using DispatcherTimer? Unfortunately app need's to run in slow PC's and DispatcherTimer continuously increasing memory usage. I check that in WPF Performance Profiling Tool and that's true - CPU usage with 1sec timespan is ~5-15%. And becouse im using class to get time value and show that on label, it would be great if method to show could run without xaml-generated controls.

Thanks!

@EDIT:

DispatcherTimer dispatcherTimer = new DispatcherTimer(); 
dispatcherTimer.Tick += new EventHandler(dispatcherTimer_Tick); 
dispatcherTimer.Interval = new TimeSpan(0, 0, 0); 
dispatcherTimer.Start(); 

and when tick:

private void dispatcherTimer_Tick(object sender, EventArgs e) 
{ 
lbl.Content = DateTime.Now.ToString("F"); 
// lbl is static label which i create once and show i several windows. 
}
user13657
  • 745
  • 3
  • 17
  • 36
  • 1
    Oo - can you show us the implementation of the `DispatcherTimer`. Normally, I wouldn't expect the memory to grow. So let's have a look, if you have produced a memory leak. ;o) – DHN Jun 03 '13 at 13:12
  • You need to "get" the current time someway. Whether it's wrapped in a helper or out-of-box. I'd guess if there's a noticable performance blip in your run-time, your doing something weird with your `Timer`. – Viv Jun 03 '13 at 13:12
  • First of all - is "Dispatcher Invoke" in WPF Performance Tol means running DispatcherTimer ? I think so, becouse when i commend that code, its now like 0 to 1-2 % (test for 10 min). – user13657 Jun 03 '13 at 13:27
  • Well i guess i missundersood Dispatcher Invoke and DispatcherTimer.. – user13657 Jun 03 '13 at 13:49

1 Answers1

4

Your interval is zero, meaning...ouch. Why is it necessary to update the UI more than 10 times a second? No human being will be able to process the changes if they are that frequent. By default WPF only updates the screen 60 times a second, so your interval should be at least 1000/60 = 16.6 ms. However, I'd argue that something as high as 250ms could be good enough.

Kent Boogaart
  • 175,602
  • 35
  • 392
  • 393