Xamarin.ios C#/MonoTouch实现一个秒表,在标签上动态显示时间

Xamarin.ios C#/MonoTouch实现一个秒表,在标签上动态显示时间,xamarin.ios,stopwatch,Xamarin.ios,Stopwatch,是否可以实现一个秒表,在表运行时显示标签上的秒表值变化 我使用以下代码添加了秒表 Stopwatch stopwatch = new Stopwatch(); // Begin timing stopwatch.Start(); // Stop timing stopwatch.Stop(); 如何在标签上显示运行时间???使用a而不是a 谢谢,杰森,成功了。问题是它没有用该值更新标签。我想知道为什么?我使用MonoTouch进行开发,我有一个标签,我想更新使用Interface build

是否可以实现一个秒表,在表运行时显示标签上的秒表值变化

我使用以下代码添加了秒表

Stopwatch stopwatch = new Stopwatch();
// Begin timing
stopwatch.Start();

// Stop timing
stopwatch.Stop();
如何在标签上显示运行时间???

使用a而不是a


谢谢,杰森,成功了。问题是它没有用该值更新标签。我想知道为什么?我使用MonoTouch进行开发,我有一个标签,我想更新使用Interface builder创建的标签需要时间。它说线程已启动,但未更新标签。任何关于如何处理它的想法,你都需要包含一个代码示例,显示你是如何更新标签的。您是否使用InvokeOnMainThread更新UI?不,我没有使用InvokeOnMainThread。这与您在上面的private static void OnTimedEvent(对象源,ElapsedEventArgs e)中详细介绍的代码相同{//在这里更新标签label1.Text=“value”;}
// create a timer that fires every 10 ms
Timer aTimer = new Timer(10);

// Hook up the Elapsed event for the timer.
aTimer.Elapsed += new ElapsedEventHandler(OnTimedEvent);

aTimer.Enabled = true;

private static void OnTimedEvent(object source, ElapsedEventArgs e)
{
    // update your label here
}