非常简单的WPF程序会在键盘布局更改时锁定(挂起) [英] Very simple WPF program locks up (hangs) on keyboard layout change

查看:54
本文介绍了非常简单的WPF程序会在键盘布局更改时锁定(挂起)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

每当用户通过组合键更改键盘布局时,以下程序都会可锁定.如果通过托盘小程序更改了键盘布局,则不会锁定.将布局更改为英语时,它不会锁定.如果 Task 从不执行,它不会锁定.

XAML:

 < StackPanel>< TextBox></TextBox>< Button Click ="Button_Click">点击我</Button></StackPanel> 

C#:

  private void Button_Click(对象发送者,RoutedEventArgs e){Task.Factory.StartNew(()=>{var visual = new DrawingVisual();使用(var context = visual.RenderOpen()){}});} 

单击按钮之前,我可以根据需要切换键盘布局.单击后,程序将在首次尝试切换布局时锁定.

重要的是,仅当通过 Alt + Shift + 2 Ctrl + Shift + 2 (和 3 ,但不是 1 ).

要避免在后台线程上使用 DrawingVisual ,这是一种为时已晚的方式.这已成为该产品不可或缺的核心功能.任何解决此问题的想法都非常欢迎.

此错误在.NET 4.0,Win7 32位和64位上重现.

赏金:此错误按百分比影响很少有人,但每次他们习惯通过以下方式更改键盘布局时,所影响的那些人都会不断导致锁定(并造成相应的数据丢失)捷径.我想要一种变通方法,它不会改变某些视觉效果在单独的线程上呈现的事实.

解决方案

C#:

private void Button_Click(object sender, RoutedEventArgs e)
{
    Task.Factory.StartNew(() =>
    {
        var visual = new DrawingVisual();
        using (var context = visual.RenderOpen())
        {
        }
    });
}

Before the button click, I can switch keyboard layouts as I please. After the click the program locks up on the first attempt to switch layouts.

Importantly, this bug only occurs if the layouts are switched via Alt+Shift+2 or Ctrl+Shift+2 (and 3, but not 1).

It’s way, way too late to avoid the use of DrawingVisual on background threads. This has become an integral, core feature of the product. Any ideas for how to work around this are very welcome.

This bug reproduces on .NET 4.0, Win7 32-bit and 64-bit.

Bounty: this bug affects few people in terms of percentage, but those it does affect will constantly cause the lock-up (with the corresponding data loss) every time they habitually change the keyboard layout via the shortcut. I'd like a work-around which does not change the fact that some visuals are rendered on a separate thread.

解决方案

Official Microsoft answer:

This issue will no[t] be addressed in the next release of WPF. -WPF Team.

I’m guessing they’re all too busy with WinRT and WPF is on the back burner.

这篇关于非常简单的WPF程序会在键盘布局更改时锁定(挂起)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆