Windows Phone 8 定时器 [英] Timer for Windows Phone 8

查看:19
本文介绍了Windows Phone 8 定时器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望以 1 分钟左右的时间间隔执行一个函数.我如何才能在 Windows Phone 8 中实现这一点.

我不是在寻找 后台代理.该应用程序将在前台运行.我有哪些选择?

I wish to execute a function at an interval of 1 or so minutes. How can I achieve this in Windows Phone 8.

I am not looking for background agents. The app will be running in the foreground. What are my options?

推荐答案

您可以使用 DispatcherTimer 类

you can use the DispatcherTimer Class

private DispatcherTimer dispatcherTimer;
    // Constructor
    public MainPage()
    {

        InitializeComponent();
        dispatcherTimer = new System.Windows.Threading.DispatcherTimer();
        dispatcherTimer.Tick += new EventHandler(dispatcherTimer_Tick);
        dispatcherTimer.Interval = new TimeSpan(0, 0, 1);
        dispatcherTimer.Start();

    }

  private void dispatcherTimer_Tick(object sender, EventArgs e)
  {
    //do whatever you want to do here
  }

参考:(http://msdn.microsoft.com/en-us/library/system.windows.threading.dispatchertimer(v=vs.110).aspx)

这篇关于Windows Phone 8 定时器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆