I'm trying to update the Text of a TextBlock
every time a timer fires. Here is my code:
public static DateTime startTime;
System.Timers.Timer timer = new System.Timers.Timer(1000);
timer.AutoReset = true;
timer.Elapsed += Timer_Tick;
timer.Start();
private void Timer_Tick(object sender, EventArgs e)
{
timerLabel.Text = DateTime.Now.Subtract(startTime).ToString(@"hh\:mm\:ss");
}
When I run it I get Exception thrown: 'System.Runtime.InteropServices.COMException' in WinRT.Runtime.dll
. All other code I put in that function will run, it just won't update the text of my TextBlock.
I've also tried with a System.Threading.Timer
and get the same error.
How can I fix this to update the Text of my TextBlock every time a second elapses? Every answer I find doesn't seem to work with WinUI 3.