title author date CreateTime categories
WPF shows that some windows in multithreading will be locked in the PenThreadWorker constructor when the application starts
lindexi
2019-06-14 08:50:36 +0800
2019-06-11 19:28:43 +0800
WPF

Problem description:
WPF will initialize pen thread when the window initializing. But I find the window may be locked in PenThreadWorker constructor.
The UnsafeNativeMethods.CreateResetEvent will lock the thread.

Actual behavior:
I use multithreading to create some windows by this code and maybe the thread be locked in PenThreadWorker constructor.
The Demo code

    public partial class App : Application
{
/// <inheritdoc />
protected override void OnStartup(StartupEventArgs e)
{
var thread = new Thread(() =>
{
var mainWindow = new MainWindow();
mainWindow.Show();
Dispatcher.Run();
});
thread.SetApartmentState(ApartmentState.STA);
thread.Start();
base.OnStartup(e);
}
}

The step

  1. Run the code
  2. Use the VisualStudio to suspend the application
    Maybe you can find the application only create a Stylus Input thread and show only a main window and the other main window and the thread be locked in PenThreadWorker constructor and the window can not show
    Why I need multithreading to show the windows? I need the splash window to show the welcome page and then I should show the main window in other thread to do the bussiness code and I should close the splash window when the main window showed.
    But I found some users could not show the main window and the main window be lock in PenThreadWorker constructor.
    I use dnspy to suspend the application and find the code run in PenThreadWorker constructor and the UnsafeNativeMethods.CreateResetEvent will lock the thread.
 PenThreadWorker..ctor()
PenThread..ctor()
PenThreadPool.GetPenThreadForPenContextHelper(PenContext penContext)
PenThreadPool.GetPenThreadForPenContext(PenContext penContext)
WispTabletDeviceCollection.UpdateTabletsImpl()
WispTabletDeviceCollection.UpdateTablets()
WispTabletDeviceCollection..ctor()
WispLogic.get_WispTabletDevices()
WispLogic.RegisterHwndForInput(InputManager inputManager, PresentationSource inputSource)
HwndStylusInputProvider..ctor(HwndSource source)
HwndSource.Initialize(HwndSourceParameters parameters)
HwndSource..ctor(HwndSourceParameters parameters)
PresentationFramework.dll!System.Windows.Window.CreateSourceWindow(bool duringShow)
PresentationFramework.dll!System.Windows.Window.CreateSourceWindowDuringShow()
PresentationFramework.dll!System.Windows.Window.ShowHelper(object booleanBox)

Expected behavior:
The UnsafeNativeMethods.CreateResetEvent do not lock the thread

Minimal repro:

Create a empty WPF application and then change the app.xaml.cs code

    public partial class App : Application
{
/// <inheritdoc />
protected override void OnStartup(StartupEventArgs e)
{
var thread = new Thread(() =>
{
var mainWindow = new MainWindow();
mainWindow.Show();
Dispatcher.Run();
});
thread.SetApartmentState(ApartmentState.STA);
thread.Start();
base.OnStartup(e);
}
}

Run the code and maybe you can find one of the main window can not show and it stop in UnsafeNativeMethods.CreateResetEvent and I wait for a hour but it can not run.

2019-6-14-WPF-shows-that-some-windows-in-multithreading-will-be-locked-in-the-PenThreadWorker-constr...的更多相关文章

  1. 每日一练ACM 2019.04.14

    2019.4.14 第1001题:Sum Problem Problem DescriptionHey, welcome to HDOJ(Hangzhou Dianzi University Onli ...

  2. 通过 AppSwitch 禁用 WPF 内置的触摸让 WPF 程序可以处理 Windows 触摸消息

    原文:通过 AppSwitch 禁用 WPF 内置的触摸让 WPF 程序可以处理 Windows 触摸消息 WPF 框架自己实现了一套触摸机制,但同一窗口只能支持一套触摸机制,于是这会禁用系统的触摸消 ...

  3. 在 WPF 程序中应用 Windows 10 真?亚克力效果

    原文:在 WPF 程序中应用 Windows 10 真?亚克力效果 从 Windows 10 (1803) 开始,Win32 应用也可以有 API 来实现原生的亚克力效果了.不过相比于 UWP 来说, ...

  4. WPF关于“在“System.Windows.Markup.StaticResourceHolder”上提供值时引发了异常。”问题解决办法

    在WPF中添加样式,在MainWindow.xaml使用自定义按钮FButton时报错,报错信息如下: "System.Windows.Markup.XamlParseException&q ...

  5. IntelliJ IDEA 最新版 2019.2.4 激活 (持续更新)(含windows和Mac)

    IntelliJ IDEA 最新版 2019.2.4 激活 最新版激活包下载地址: 百度网盘 提取码: i28c 转载: Neo Peng Jetbrains系列产品 激活方式 同下述方式相同,只需要 ...

  6. WPF 利用HwndSource拦截Windows消息

    WPF提供了一个HwndSource可以使你更快的实现处理Windows消息. 通过HwndSource.FromHwnd得到的HwndSource可以添加(AddHook)移除(Remove)Hoo ...

  7. WPF中使用System.Windows.Interactivity实现事件绑定的替代方法

    一.问题描述 对于 Button 等控件,在 MVVM 中我们能通过 Command 绑定解决 Click 事件.具体如下所示: <Button Margin="10" He ...

  8. WPF程序中处理Windows消息

    首先通过WindowInteropHelper类,我们可以获取WPF Window的Handle. WindowInteropHelper helper = new WindowInteropHelp ...

  9. WPF自定义窗口(Windows Server 2012 Style)

    先上图 新建CustomControl,名:HeaderedWindow Themes\Generic.aml文件夹下加入 笔刷,转换器 <SolidColorBrush x:Key=" ...

  10. 2019.4.14 python基础30

    前面学习的变量,数据类型(整型,浮点数,布尔),序列(字符串,列表,元祖,字典,集合) ,可以看做是数据的组织方式.数据可以看做是“砖块”! 流程控制语句是代码的组织方式,可以看做是“混凝土” 一个完 ...

随机推荐

  1. VGDB提示

    由于之前地址的版本在未安装.Net 4.0的电脑上安装会出现插件使用装载失败的问题,已更新,新地址为:http://pan.baidu.com/s/1xdnuD,此版本需要.Net 2.0.

  2. P1820 寻找AP数

    P1820 寻找AP数两个性质,分解质因数后,连续,且指数递减,dfs就完了 #include <iostream> #include <cstdio> #include &l ...

  3. leetcood学习笔记-53*-最大子列和

    题目描述: 方法一:O(N) class Solution(object): def maxSubArray(self, nums): sum = 0 max_sub_sum = nums[0] fo ...

  4. python 九九乘法口诀

    for i in range(1,10):    for j in range(1,i+1):        print(j,"*",i,"=",i*j,&qu ...

  5. SQL Server Download

    { https://www.microsoft.com/zh-cn/sql-server/sql-server-downloads }

  6. System.Web.Mvc.HttpPostAttribute.cs

    ylbtech-System.Web.Mvc.HttpPostAttribute.cs 1.程序集 System.Web.Mvc, Version=5.2.3.0, Culture=neutral, ...

  7. 海量数据解决思路之Hash算法

    海量数据解决思路之Hash算法   一.概述 本文将粗略讲述一下Hash算法的概念特性,里边会结合 分布式系统负载均衡 实例对Hash的一致性做深入探讨.另外,探讨一下Hash算法在海量数据处理方案中 ...

  8. C#winform datagridview单元格的单击处理

    首先看看效果图: 需求:要求是的在datagridview里面绑定数据后,可以任意点击想要点击的某列的单元格进行改变数据.需要在datagridview里面写3个事件 1.RowPrePaint事件: ...

  9. pinmap 和 pin allocation

    串口管脚分配

  10. PAT甲级——A1115 Counting Nodes in a BST【30】

    A Binary Search Tree (BST) is recursively defined as a binary tree which has the following propertie ...