强制DispatcherTimer勾选

时间:2013-09-06 08:37:03

标签: windows-phone-7 time

我需要每分钟发送一次服务器请求,以获取新产品列表(如果它是通过网络更改的话)。

所以,我正在使用DispatcherTimer

public static void Start()
    {
        if (timer != null) return;

        timer = new DispatcherTimer {Interval = TimeSpan.FromSeconds(0.1)};
        timer.Tick += Run;
        timer.Start();
    }

private static async void Run(object sender, EventArgs e)
    {
        timer.Interval = TimeSpan.FromSeconds(60); // TODO" add dynamic changes here
        timer.Stop();
        ** Do stuff
        timer.Start();
    }

但是,有时候,我需要强制更新。运行

是否正确
public static void ForceUpdate()
    {
        Run(null, null);
    }

编辑:我的意思是,如果做东西足够长,不会通过计时器第二次调用吗?或者也许我应该用其他东西来做这种工作?

2 个答案:

答案 0 :(得分:0)

编辑:插入一个应存储上次更新时间的变量,并检查更新是否已在某个时间间隔内完成。

答案 1 :(得分:0)

啊,好吧,这很简单

        public static void ForceUpdate()
        {
            timer.Stop();
            timer.Interval = TimeSpan.FromMilliseconds(10);
            timer.Start();
        }
相关问题