[英] WinUI 3 COMException Error when updating TextBlock Text in a timer function
我试图在每次计时器启动时更新TextBlock
的文本.这是我的代码:
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");
}
当我运行它时,我得到Exception thrown: 'System.Runtime.InteropServices.COMException' in WinRT.Runtime.dll
.我在该函数中输入的所有其他代码都将运行,它只是不会更新我的TextBlock的文本.
如何修复此问题以在每过一秒时更新TextBlock的文本?我找到的每个答案似乎都不适用于WinUI 3.