Dispatcher.BeginInvoke()延迟

时间:2013-06-13 13:15:21

标签: windows-phone-7 windows-phone-8 dispatcher

我有一些代码:

    public MainPage()
    {
         InitializeComponent();
         MyPostRequest.GetDataFromService((result) =>
         {
            Dispatcher.BeginInvoke(() => { //Update UI from web service}); 
         });
         System.Threading.Thread myThread = new System.Threading.Thread(new System.Threading.ThreadStart(MyThread));
         myThread.Start();
    }

    private void MyThread()
    {
        //do something
        Stopwatch stopwatch = new Stopwatch();
        stopwatch.Start();
        Dispatcher.BeginInvoke(() => 
        {
             stopwatch.Stop();
             long elapsedMilliseconds = stopwatch.ElapsedMilliseconds;
             Debug.WriteLine("time: {0} ms", elapsedMilliseconds);
            //update UI
        });
    }

基本上,测量的时间约为100毫秒,但很少为1000 - 5000毫秒。在升级UI之前,我检查本地数据库中的数据并对数据进行采样。我很困惑,切换到UI线程的延迟到底是什么。可能是什么问题?

0 个答案:

没有答案