gpt4 book ai didi

c# - WPF 应用程序在添加或删除平板设备后停止响应触摸

转载 作者:行者123 更新时间:2023-12-03 03:26:09 25 4
gpt4 key购买 nike

在当前 CPU 使用率较高的计算机上运行任何 WPF 应用程序,如果您同时插入和拔出 USB HID 平板设备,WPF 应用程序将停止响应触摸,仅响应鼠标。

要求:

  • 运行任何 WPF应用
  • 继续插拔 USB HID 平板设备
  • 使 CPU 使用率高

  • 我的问题:

    我们非微软开发人员有什么彻底的方法来解决这个触摸失败吗?

    我在这里发布了对触摸失败的初步分析:
  • WPF Applications Stop Responding to Touches after Adding or Removing Tablet Devices - walterlv

  • 这篇文章对于 StackOverflow 来说有点长,这里只提一些结论:
  • GetPenEventMultiple 可能存在死锁贴在下面。
  • GetTabletInfoHelper 可能还有其他线程安全问题.

  • 下面的代码来自 .NET Framework,为了便于理解,我对其进行了简化:
    // PenThreadWorker.ThreadProc
    while(There are two loops in real)
    {
    // The `break` below only exit one loop, not two.
    if (this._handles.Length == 1)
    {
    if (!GetPenEvent(this._handles[0], otherArgs))
    {
    break;
    }
    }
    else if (!GetPenEventMultiple(this._handles, otherArgs))
    {
    break;
    }
    // Other logics.
    }


    // WorkerOperationGetTabletsInfo.OnDoWork
    try
    {
    _tabletDeviceInfo = PenThreadWorker.GetTabletInfoHelper(pimcTablet);
    }
    catch(COMException)
    {
    _tabletDevicesInfo = new TabletDeviceInfo[0];
    }
    catch(ArgumentException)
    {
    _tabletDevicesInfo = new TabletDeviceInfo[0];
    }
    // Other exception handling.

    最佳答案

    如果硬件设备反复连接和断开连接,您的操作系统最终会因资源使用而崩溃、停滞或损坏内存。

    建议您将 WPF 桌面应用程序更改为不执行任何操作,直到用户连接平板电脑并单击 WPF 桌面应用程序中的按钮以“启用平板电脑”支持。

    否则,您将让一些用户使用坏的 USB 电缆反复连接和断开平板电脑。

    操作系统将无法像处理故障磁盘 Controller 一样处理设备。

    关于c# - WPF 应用程序在添加或删除平板设备后停止响应触摸,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51854593/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com