none
C# 中方法 WinRT API 反应过慢的问题? RRS feed

  • 问题

  • 连续调用同一个 WinRT API     CoreWindow.GetAsyncKeyState ,在C#中过一段时间会出现明显卡顿,

    在C++ 中无此问题,而换用另一个API  

     CoreWindow.

    GetKeyState 

    不会卡顿,但是需要点击两次,

    请问如何解决C# 中卡顿的问题,或者需要点击两次的问题?

    2013年9月27日 5:47

答案

  • 你好 Cocker,

    我就C#中多次调用CoreWindow.GetAsyncKeyState建立了一个sample,并没有重现你的问题。也就是卡顿异常并不是因为多次调用该函数。下面是我的代码:

        public MainPage()
            {
                this.InitializeComponent();
                core.KeyDown += core_KeyDown;
            }
            CoreWindow core = CoreWindow.GetForCurrentThread();
            void core_KeyDown(CoreWindow sender, KeyEventArgs args)
            {
                var virtualkey = core.GetAsyncKeyState(Windows.System.VirtualKey.Up);
                if ((virtualkey & CoreVirtualKeyStates.Down) == CoreVirtualKeyStates.Down)
                {
                    int k = int.Parse(button.Content.ToString());
                    button.Content = ++k;
                }
            }


    <font color="0099FF">&lt;THE CONTENT IS PROVIDED &quot;AS IS&quot; WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED&gt;</font><br/> Thanks<br/> MSDN Community Support<br/> <br/> Please remember to &quot;Mark as Answer&quot; the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.

    2013年10月2日 7:35
    版主

全部回复

  • Hi Cocker,

    我本地测试的时候并未发现类似的问题,你能提供一个重现的demo么?

    多谢对论坛的支持。

    --James


    <THE CONTENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED>
    Thanks
    MSDN Community Support

    Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.

    2013年9月27日 7:45
    版主
  • C++ 代码就是 Win8 Sdk 中的 Direct3D bump mapping sample

    这是我根据这个代码改写的C#版本

    在 LonLatController.cs 文件中替换这两个API 

    https://skydrive.live.com/redir?resid=DDA638A411D8618B!995&authkey=!ACt64oLFiSYwznM

    键盘点击旋转的时候,一会儿就卡顿了
    2013年9月27日 8:16
  • 你好,

    你所给的C#版本的连接不可用,请检查。

    如果你那里可以使用的话,应该是我的网络受限了,最好使用 SkyDrive 来共享你的代码。


    <font color="0099FF">&lt;THE CONTENT IS PROVIDED &quot;AS IS&quot; WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED&gt;</font><br/> Thanks<br/> MSDN Community Support<br/> <br/> Please remember to &quot;Mark as Answer&quot; the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.

    2013年9月27日 9:03
    版主
  • 已修改,谢谢
    2013年9月27日 9:24
  • 你好 Cocker,

    我就C#中多次调用CoreWindow.GetAsyncKeyState建立了一个sample,并没有重现你的问题。也就是卡顿异常并不是因为多次调用该函数。下面是我的代码:

        public MainPage()
            {
                this.InitializeComponent();
                core.KeyDown += core_KeyDown;
            }
            CoreWindow core = CoreWindow.GetForCurrentThread();
            void core_KeyDown(CoreWindow sender, KeyEventArgs args)
            {
                var virtualkey = core.GetAsyncKeyState(Windows.System.VirtualKey.Up);
                if ((virtualkey & CoreVirtualKeyStates.Down) == CoreVirtualKeyStates.Down)
                {
                    int k = int.Parse(button.Content.ToString());
                    button.Content = ++k;
                }
            }


    <font color="0099FF">&lt;THE CONTENT IS PROVIDED &quot;AS IS&quot; WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED&gt;</font><br/> Thanks<br/> MSDN Community Support<br/> <br/> Please remember to &quot;Mark as Answer&quot; the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.

    2013年10月2日 7:35
    版主
  • 无疑,应该是我的电脑落伍了,只有老实改回C++了
    2013年10月8日 12:53