简体   繁体   English

Xamarin Forms UI线程不起作用

[英]Xamarin Forms UI Thread not working

I am trying to create a countdown timer inside a thread that will be updated in the UI of my application. 我正在尝试在将在我的应用程序的UI中更新的线程内创建一个倒数计时器。 I have a problem using the reference `System.Threading.Thread. 我在使用参考`System.Threading.Thread时遇到问题。

using System.Globalization;
using System.Threading;

new System.Threading.Thread(new System.Threading.ThreadStart(() =>
        {
            InvokeOnMainThread(() =>
           {
                this.timer1 = this.timer1.AddDays(16);
               this.timer1 = this.timer1.AddMonths(10);
               this.timer1 = this.timer1.AddYears(2015);

               this.timer2 = DateTime.Now;


               this.result = this.timer1.Subtract(this.timer2);

               nbJour = this.result.Days.ToString();
               nbHeure = this.result.Hours.ToString();
               nbMin = this.result.Minutes.ToString();

           });

        })).Start();

Thread and ThreadStart() are underlined red, with no error message. ThreadThreadStart()带有红色下划线,没有错误消息。

使用Device.BeginInvokeOnMainThread代替InvokeOnMainThread或使用Task

Device.BeginInvokeOnMainThread( () => { ... } );

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM