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. dubbo重连机制会不会造成错误

    dubbo在调用服务不成功时,默认会重试2次. Dubbo的路由机制,会把超时的请求路由到其他机器上,而不是本机尝试,所以 dubbo的重试机器也能一定程度的保证服务的质量. 但是如果不合理的配置重试 ...

  2. animation,transition,transform小练习

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  3. python使用PIL处理图片后返回给前端的坑

    一.python代码 这里有个坑,之前没有将bytes图片数据转成base64就返回到前端了,但在前端处理的时候,怎么都显示不出图片来,虽然数据拿到了,但bytes被传到前后变str了,所以怎么搞都没 ...

  4. mongodb操作指令(一):数据库,集合,文档

    数据库 查看所有数据库 show dbs 查看当前数据库 db 创建使用数据库use runoob 删除数据库 db.dropDatabase() 集合 创建集合db.createCollection ...

  5. UVA-699-The Falling Leaves-二叉树+递归

    Each year, fall in the North Central region is accompanied by the brilliant colors of the leaves on ...

  6. 9.1 mongo_python.py

    # 安装 pymongo pip install pymongo import pymongo try: # 1.链接mongod的服务 mongo_py = pymongo.MongoClient( ...

  7. 滑雪 矩阵中的最长上升路径 /// 记忆化DFS || DP oj22919

    大致题意: Description 难怪Michael喜欢滑雪,因为滑雪确实很刺激.为了获得加速度,滑雪道必须向下倾斜,而且当滑到坡底,你不得不再次走上坡或者等待升降机来载你.Michael想知道在一 ...

  8. 关于jar包启动遇到的问题

    一.找不到propertites文件,错误如下 原因是打成的jar不包含classpath信息,需要运行时指定,命令为 -Xbootclasspath/a: 后缀在核心class搜索路径后面.常用! ...

  9. Sky Code

    Sky Code 给出n个数,求选出4个数组合,使其gcd为1,,\(n<=10000\),每个数\(<=10000\). 解 理解1:容斥原理 注意到Mobius反演式子不好写出,于是我 ...

  10. ActiveMQ 知识点

    消息队列高可用 持久化,事务,签收,zookeeper+replicated-leveldb-store的主从集群 异步发送 同步发送: 明确指定同步发送 未使用事务的前提下,发送持久化消息(会使用同 ...