简体   繁体   English

添加或删除平板电脑设备后,WPF 应用程序停止响应触摸

[英]WPF applications stop responding to touches after adding or removing tablet devices

Run any WPF application on a computer which is currently has a high CPU usage, if you keep plugging and unplugging a USB HID tablet device at the same time, the WPF applications will stop responding to touches and only respond to mouse.在当前 CPU 使用率较高的计算机上运行任何 WPF 应用程序,如果您同时插入和拔出 USB HID 平板设备,WPF 应用程序将停止响应触摸而仅响应鼠标。

The requirements:要求:

  1. Run any WPF application运行任何WPF 应用程序
  2. Keep plugging and unplugging a USB HID tablet device继续插入和拔出 USB HID 平板设备
  3. Make a high CPU usage使 CPU 使用率高

My question:我的问题:

Is there any thorough way for us non-Microsoft developers do to fix this touch failure?对于我们非 Microsoft 开发人员来说,有没有什么彻底的方法可以解决此触摸失败问题?


I've posted the preliminary analysis of the touch failure here:我在这里发布了触摸失败的初步分析:

This article is a bit long for StackOverflow, so I only mention some conclusion here:这篇文章对于StackOverflow来说有点长,所以我在这里只提一些结论:

  • There may be a deadlock for GetPenEventMultiple posted below.下面发布的GetPenEventMultiple可能会出现死锁。
  • There may be other thread-safety issues of GetTabletInfoHelper . GetTabletInfoHelper可能存在其他线程安全问题。

The code below is from .NET Framework and I simplified them for easier understanding:下面的代码来自 .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.

Your operating system will ultimately crash, bog down due to resource usage, or otherwise corrupt memory if the hardware device is repeatedly connected and disconnected.如果硬件设备反复连接和断开连接,您的操作系统最终将因资源使用而崩溃、停滞或以其他方式损坏内存。

Suggest you change the WPF desktop application to do nothing until the user connects the tablet and clicks on a button in the WPF desktop application to "Enable Tablet" support.建议您将 WPF 桌面应用程序更改为不执行任何操作,直到用户连接平板电脑并单击 WPF 桌面应用程序中的按钮以“启用平板电脑”支持。

Otherwise, you will get some user with a bad USB cable repeatedly connecting and disconnecting the tablet.否则,您会得到一些用户使用坏的 USB 电缆反复连接和断开平板电脑。

The OS won't be able to handle the device the same as if it is a faulty disk controller.操作系统将无法像处理有故障的磁盘控制器那样处理设备。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM