using Microsoft.Maui.Controls;
using System.Timers;

public partial class MainPage : ContentPage
{
    private Timer _timer;

    public MainPage()
    {
        InitializeComponent();

        _timer = new Timer(1000);
        _timer.Elapsed += OnTimerElapsed;
    }

    private void OnTimerElapsed(object sender, ElapsedEventArgs e)
    {
        // 在这里添加您需要执行的代码
        System.Diagnostics.Debug.WriteLine($"Timer ticked at {e.SignalTime}");
    }

    private void StartTimerButton_Clicked(object sender, EventArgs e)
    {
        _timer.Start();
    }

    private void StopTimerButton_Clicked(object sender, EventArgs e)
    {
        _timer.Stop();
    }
}
文档更新时间: 2023-11-16 21:09   作者:admin