WPF .NET应用程序崩溃,ComboBox和Menu事件未在使用Windows 10 Creators Update,.NET 4.7或KB4034658

时间:2017-08-16 19:17:51

标签: c# .net wpf windows tablet

当我用ComboBox上的笔点击摇晃/紧张/锤击时,点击这些项目,在点击时移动笔...... 5或10分钟后控制停止工作。
然后我可以打开ComboBox,可以点击一个项目,项目会突出显示,但没有任何反应:ComboBox没有关闭,也没有点击事件被触发。
ContextMenu也会发生同样的错误。当错误发生时,所有ComboBox和所有菜单都不再起作用。 当我用笔或用我的手指点击时,即使用笔或手指不能再使用控件,鼠标也能正常工作。

在正常使用情况下,每个工作日大约发生5次,对我的用户来说非常烦人。 你需要一些耐心"为了得到错误的复制,也许你需要超过10分钟...但它确实发生了。

我用一个ComboBox和一个带有ContextMenu的按钮制作了一个简单的测试应用程序,你可以用它重新产生错误。
我的应用程序的目标框架是4.6.1,使用VS2015编译。我的应用程序适用于Windows 8.1和Windows 10 Anniversary,使用.NET 4.6.1和4.6.2。

Microsoft Surface Pro 3和Pro 4上发生错误   - Windows 10 Creators更新(包括.NET 4.7)
  - 安装了Windows 10周年更新和.NET 4.7   - 安装了Windows 8.1和.NET 4.7   - 安装了Windows 10周年更新(.NET 4.6.2)和KB4034658 !!!

对于前三个场景,我发现如何阻止Creator Update和.NET 4.7被Windows Update安装,至少在接下来的6个月内。 但是对于2017年8月的累积更新KB4034658,我的Windows 10用户的当前选项要么存在错误,要么完全停用所有Windows更新。

以下是我的测试应用的代码:

MainWindow.xaml

<Window x:Class="MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:DotNet47ComboBoxAndMenuError"
        mc:Ignorable="d"
        Title="" Height="900" Width="715" WindowStartupLocation="Manual" WindowState="Maximized">
    <Grid>
        <WrapPanel>
            <ComboBox FontSize="16" Width="150">
                <ComboBoxItem>ComboBoxItem 1</ComboBoxItem>
                <ComboBoxItem>ComboBoxItem 2</ComboBoxItem>
                <ComboBoxItem>ComboBoxItem 3</ComboBoxItem>
                <ComboBoxItem>ComboBoxItem 4</ComboBoxItem>
                <ComboBoxItem>ComboBoxItem 5</ComboBoxItem>
                <ComboBoxItem>ComboBoxItem 6</ComboBoxItem>
                <ComboBoxItem>ComboBoxItem 7</ComboBoxItem>
                <ComboBoxItem>ComboBoxItem 8</ComboBoxItem>
                <ComboBoxItem>ComboBoxItem 9</ComboBoxItem>
            </ComboBox>
            <Button x:Name="btnMenu" Content="MENU" FontSize="16" Margin="100,0,0,0">
                <Button.ContextMenu>
                    <ContextMenu>
                        <MenuItem Header="MenuItem 1"></MenuItem>
                        <MenuItem Header="MenuItem 2"></MenuItem>
                        <MenuItem Header="MenuItem 3"></MenuItem>
                        <MenuItem Header="MenuItem 4"></MenuItem>
                        <MenuItem Header="MenuItem 5"></MenuItem>
                        <MenuItem Header="MenuItem 6"></MenuItem>
                        <MenuItem Header="MenuItem 7"></MenuItem>
                        <MenuItem Header="MenuItem 8"></MenuItem>
                        <MenuItem Header="MenuItem 9"></MenuItem>
                    </ContextMenu>
                </Button.ContextMenu>
            </Button>
        </WrapPanel>
    </Grid>
</Window>

只有XAML,我的测试应用中绝对没有代码。

我的用户还报告偶尔点击按钮在对话框窗口中不执行任何操作。发生这种情况时,他们只能点击右上方的关闭按钮;下拉菜单和菜单不再在主窗口中工作,如上所述:他们需要关闭并重新启动应用程序。没有用样本再现这个,我猜它也是同样的错误。

此外,我的应用程序偶尔会与Windows 10 Creators Update或.NET 4.7崩溃,可能还会与KB4034658崩溃。不幸的是,我不清楚这些崩溃何时发生,但我怀疑它们在某种程度上与上述问题有关。

来自Windows事件日志的示例崩溃信息:

      <Category>0</Category>
      <ComputerName>DESKTOP-XXXXXX</ComputerName>
      <EventCode>1026</EventCode>
      <EventIdentifier>1026</EventIdentifier>
      <EventType>1</EventType>
      <InsertionStrings>Application: MyApp.exe
Framework Version: v4.0.30319
Description: The process was terminated due to an unhandled exception.
Exception Info: System.IndexOutOfRangeException
   at System.Collections.Generic.Dictionary`2[[System.__Canon, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089],[System.__Canon, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]].Insert(System.__Canon, System.__Canon, Boolean)
   at System.Windows.Input.StylusWisp.WispLogic.CoalesceAndQueueStylusEvent(System.Windows.Input.RawStylusInputReport)
   at System.Windows.Input.PenContext.FirePackets(Int32, Int32[], Int32)
   at System.Windows.Input.PenThreadWorker.FlushCache(Boolean)
   at System.Windows.Input.PenThreadWorker.FireEvent(System.Windows.Input.PenContext, Int32, Int32, Int32, Int32, IntPtr)
   at System.Windows.Input.PenThreadWorker.ThreadProc()
   at System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)
   at System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)
   at System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object)
   at System.Threading.ThreadHelper.ThreadStart()

</InsertionStrings>
      <Logfile>Application</Logfile>
      <Message>Application: MyApp.exe
Framework Version: v4.0.30319
Description: The process was terminated due to an unhandled exception.
Exception Info: System.IndexOutOfRangeException
   at System.Collections.Generic.Dictionary`2[[System.__Canon, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089],[System.__Canon, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]].Insert(System.__Canon, System.__Canon, Boolean)
   at System.Windows.Input.StylusWisp.WispLogic.CoalesceAndQueueStylusEvent(System.Windows.Input.RawStylusInputReport)
   at System.Windows.Input.PenContext.FirePackets(Int32, Int32[], Int32)
   at System.Windows.Input.PenThreadWorker.FlushCache(Boolean)
   at System.Windows.Input.PenThreadWorker.FireEvent(System.Windows.Input.PenContext, Int32, Int32, Int32, Int32, IntPtr)
   at System.Windows.Input.PenThreadWorker.ThreadProc()
   at System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)
   at System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)
   at System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object)
   at System.Threading.ThreadHelper.ThreadStart()
</Message>
      <RecordNumber>250</RecordNumber>
      <SourceName>.NET Runtime</SourceName>
      <TimeGenerated>8/1/2017 2:10:56 PM</TimeGenerated>
      <TimeWritten>8/1/2017 2:10:56 PM</TimeWritten>
      <Type>Error</Type>

第二个样本:

      <Category>0</Category>
      <ComputerName>DESKTOP-XXXXXX</ComputerName>
      <EventCode>1026</EventCode>
      <EventIdentifier>1026</EventIdentifier>
      <EventType>1</EventType>
      <InsertionStrings>Application: MyApp.exe
Framework Version: v4.0.30319
Description: The process was terminated due to an unhandled exception.
Exception Info: System.ArgumentNullException
   at System.Collections.Generic.Dictionary`2[[System.__Canon, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089],[System.__Canon, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]].FindEntry(System.__Canon)
   at System.Collections.Generic.Dictionary`2[[System.__Canon, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089],[System.__Canon, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]].TryGetValue(System.__Canon, System.__Canon ByRef)
   at System.Windows.Input.StylusLogic.ProcessInputReport(System.Windows.Input.RawStylusInputReport)
   at System.Windows.Input.PenContext.FirePenOutOfRange(Int32, Int32)
   at System.Windows.Input.PenThreadWorker.ThreadProc()
   at System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)
   at System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)
   at System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object)
   at System.Threading.ThreadHelper.ThreadStart()

</InsertionStrings>
      <Logfile>Application</Logfile>
      <Message>Application: MyApp.exe
Framework Version: v4.0.30319
Description: The process was terminated due to an unhandled exception.
Exception Info: System.ArgumentNullException
   at System.Collections.Generic.Dictionary`2[[System.__Canon, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089],[System.__Canon, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]].FindEntry(System.__Canon)
   at System.Collections.Generic.Dictionary`2[[System.__Canon, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089],[System.__Canon, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]].TryGetValue(System.__Canon, System.__Canon ByRef)
   at System.Windows.Input.StylusLogic.ProcessInputReport(System.Windows.Input.RawStylusInputReport)
   at System.Windows.Input.PenContext.FirePenOutOfRange(Int32, Int32)
   at System.Windows.Input.PenThreadWorker.ThreadProc()
   at System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)
   at System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)
   at System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object)
   at System.Threading.ThreadHelper.ThreadStart()
</Message>
      <RecordNumber>534</RecordNumber>
      <SourceName>.NET Runtime</SourceName>
      <TimeGenerated>7/31/2017 1:13:39 PM</TimeGenerated>
      <TimeWritten>7/31/2017 1:13:39 PM</TimeWritten>
      <Type>Error</Type>

我在https://connect.microsoft.com/VisualStudiohttps://github.com/Microsoft/dotnet/issues

报告了错误

我不希望得到这个错误的解决方案,但欢迎任何想法。

我想知道错误是否仅在MS Surface上发生。我没有发现有关此错误的其他帖子,所以我会这么认为。没有很好的机会很快得到修复...... WPF 表面 - 太异国情调了。

有了这篇文章,我希望一些拥有Surface的人会重新产生错误并向微软报告这个错误,以增加MS尽快修复它的可能性。 此外,我想知道这个错误是仅在MS Surface Tablets上发生,还是在其他平板电脑上发生,可能只在High-DPI平板电脑上发生?

2 个答案:

答案 0 :(得分:0)

我们找到了一种解决方法,但它也有一些缺点。在应用程序启动时disabling the RealTimeStylus,我们无法再重现该问题。

但是,禁用RealTimeStylus也会使用触摸功能禁用ScrollViewer swiping。它也可能影响手写笔的使用,我无法测试它。

虽然这个解决方案不是最优的,但对你的情况来说可能就足够了(或者至少是一个起点)。

    public static void DisableWPFTabletSupport()
    {
        // Get a collection of the tablet devices for this window.  
        TabletDeviceCollection devices = System.Windows.Input.Tablet.TabletDevices;

        if (devices.Count > 0)
        {
            // Get the Type of InputManager.
            Type inputManagerType = typeof(System.Windows.Input.InputManager);

            // Call the StylusLogic method on the InputManager.Current instance.
            object stylusLogic = inputManagerType.InvokeMember("StylusLogic",
                        BindingFlags.GetProperty | BindingFlags.Instance | BindingFlags.NonPublic,
                        null, InputManager.Current, null);

            if (stylusLogic != null)
            {
                //  Get the type of the device class.
                Type devicesType = devices.GetType();

                // Loop until there are no more devices to remove.
                int count = devices.Count + 1;

                while (devices.Count > 0)
                {
                    // Remove the first tablet device in the devices collection.
                    devicesType.InvokeMember("HandleTabletRemoved", BindingFlags.InvokeMethod | BindingFlags.Instance | BindingFlags.NonPublic, null, devices, new object[] { (uint)0 });

                    count--;

                    if (devices.Count != count)
                    {
                        throw new Win32Exception("Unable to remove real-time stylus support.");
                    }
                }
            }
        }
    }

答案 1 :(得分:0)

这个问题又回来了,但是我对“不再响应GUI”有一个解释。

如果某项在列表视图中(存入)不是100%可见,并且您执行了单击操作,则列表视图将首先滚动该项目完全可见。一切都可以用鼠标操作。但是TouchUp事件会在滚动之前触发。这正是错误发生的地方。 我通过等待“点击事件”来绕过此操作,无论是触摸还是鼠标,都是10毫秒,然后才执行我的操作。 因此,错误已由我解决。