什么是Windows Phone 8.1中开始调用的替代方法

时间:2015-01-02 12:24:13

标签: c# windows-phone-8

static long dd = 0, hh = 0, mm = 0, ss = 0, ms = 0;

    static Stopwatch stopwatch = new Stopwatch();

    Timer stopwatch_timer;

    static Boolean Stp = true;

private void Start_Click(object sender, RoutedEventArgs e) // Stopwatch start 
    {

        Stp = false;
        stopwatch_timer = new Timer(new TimerCallback(updatedisplay), TimerDisplay, 0, 100);
        stopwatch.Start();

    }

    private void updatedisplay(object displayblock)
    {
        ms = stopwatch.ElapsedMilliseconds;
        TextBox Bd = (TextBox)displayblock;
        ss = ms / 1000; ms = ms % 1000;
        mm = ss / 60; ss = ss % 60;
        hh = mm / 60; mm = mm % 60;
        dd = hh / 24; hh = hh % 24;
        Bd.Dispatcher.BeginInvoke(delegate() { Bd.Text = dd.ToString("00") + ":" + hh.ToString("00") + ":" + mm.ToString("00") + ":" + ss.ToString("00") + ":" + ms.ToString("000"); });

    } //Cant use begin Invoke Error - Windows.Ui.Core.Coredispatcher doesn't contain definition for Begin Invoke

我想知道Begin Invoke的替代方法以及如何实现它。很少有细节和例子会有很大的帮助。

1 个答案:

答案 0 :(得分:0)

Dispatcher.BeginInvoke( () => {});

替换为

private async Task MyMethod()
{
    await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () => { });
}