Refreshing Label content every second WPF
I'm trying to refresh a label content every second. So I define two
methods as below. I use startStatusBarTimer() in my constructor of Window.
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 a different thread
owns it.
What is wrong? Or What can I do?
No comments:
Post a Comment