Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/xamarin/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何使计时器在不冻结页面的情况下运行_C#_Xamarin - Fatal编程技术网

C# 如何使计时器在不冻结页面的情况下运行

C# 如何使计时器在不冻结页面的情况下运行,c#,xamarin,C#,Xamarin,我正在制作xamarin欢迎页面的SlashsScreen页面 我想实现计时器,它将在5秒后关闭SlashScreen。 并在xaml中显示秒数 <Label TextColor="Black" FontSize= "20" Text="{Binding timerSecond}"/> 谢谢您的帮助。这是未经测试的。但它应该对你有用 public分部类slashsscreen:ContentPage { int_timersecond=5; 公共SlashScreen() {

我正在制作xamarin欢迎页面的SlashsScreen页面

我想实现计时器,它将在5秒后关闭
SlashScreen
。 并在xaml中显示秒数

<Label TextColor="Black" FontSize= "20"  Text="{Binding timerSecond}"/>

谢谢您的帮助。

这是未经测试的。但它应该对你有用

public分部类slashsscreen:ContentPage
{
int_timersecond=5;
公共SlashScreen()
{
初始化组件();
}
出现时受保护的覆盖无效()
{
Device.StartTimer(TimeSpan.FromSeconds(1),()=>
{
_时光流逝;
timesecond.Text=\u timersecond.ToString();

如果(_timer建议您需要在类级别声明计时器。Toma我不知道为什么在这之后,它会给我一个空白页。而且它根本没有更改计时器文本。我不知道原因,伙计,计时器没有任何规范。调试它,看看发生了什么。尝试为
timeSecound
添加默认文本,如果您可以看到它,请在页面外观是默认的,但没有改变。
是否已过
触发器?如果否,请尝试将计时器移动到
SlashScreen()
中。我认为
SlashScreen()
在出现
之前触发或移动
计时器。Start()
上出现
是,它已被触发
public partial class SlashScreen : ContentPage
{
    int timerSecond = 5;

    public SlashScreen()
    {
        InitializeComponent();
    }

    protected override void OnAppearing()
    {
        var timer = new System.Timers.Timer(1000);
        timer.Start();
        timer.Elapsed += (obj, args) =>
        {

            if (timerSecond == 0)
            {
                timer.Stop();
                Application.Current.MainPage = new MainPage();
            }
            else
            {
                timerSecond--;
            }
        };

    }
}