none
关于使用CoreWindow类的线程问题 RRS feed

  • 问题

  • private void Button_Click(object sender, RoutedEventArgs e)
    {
                Point SetPoint = new Point(50, 50);
                Point GetPoint = new Point();
                CoreWindow SetMouse = CoreApplication.CreateNewView().CoreWindow;
                GetPoint = SetMouse.PointerPosition;
                string MousePos = GetPoint.ToString();
    }


            private void Button_Click(object sender, RoutedEventArgs e)
            {
                Task a = Task.Run(() => MouseABC());
            }
            private void MouseABC()
            {
                Point SetPoint = new Point(50, 50);
                Point GetPoint = new Point();
                CoreWindow SetMouse = CoreApplication.CreateNewView().CoreWindow;
                GetPoint = SetMouse.PointerPosition;
                string MousePos = GetPoint.ToString();
            }

    如上图所示,我在创建CoreWindow实例时总是会提示出如下图的错误:

    请问这是什么原因,如何解决?谢谢。

    2018年2月25日 3:42

全部回复

  • 你好,

    你可以尝试下使用 CoreDispatcher

    await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () => {
                // code here
    });


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    2018年3月9日 2:54