简体   繁体   中英

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.

The requirements:

  1. Run any WPF application
  2. Keep plugging and unplugging a USB HID tablet device
  3. Make a high CPU usage

My question:

Is there any thorough way for us non-Microsoft developers do to fix this touch failure?


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:

  • There may be a deadlock for GetPenEventMultiple posted below.
  • There may be other thread-safety issues of GetTabletInfoHelper .

The code below is from .NET Framework and I simplified them for easier understanding:

// 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.

Otherwise, you will get some user with a bad USB cable repeatedly connecting and disconnecting the tablet.

The OS won't be able to handle the device the same as if it is a faulty disk controller.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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