I try to update the contents of shortcuts every second. Therefore, I define two methods as shown below. I am using startStatusBarTimer() in my Window constructor.
codes:
private void startStatusBarTimer() { System.Timers.Timer statusTime = new System.Timers.Timer(); statusTime.Interval = 1000; statusTime.Elapsed += new System.Timers.ElapsedEventHandler(statusTimeElapsed); statusTime.Enabled = true; } private void statusTimeElapsed(object sender, ElapsedEventArgs e) { lblNow.Content = DateTime.Now.ToString("yyyy/MM/dd"); }
But I get this error:
The calling thread cannot access this object because another thread belongs to it.
What's wrong? Or what can I do?
c # wpf xaml
Babak.Abad
source share