title author date CreateTime categories
WPF will break when an exception be throw in the StylusPlugIn
lindexi
2019-10-07 12:21:19 +0800
2019-06-21 09:57:38 +0800
WPF

We can write a class that inherits the StylusPlugIn. And this class can get the touch event fast in stylus input thread in the overwrite method, such as OnStylusDown and the OnStylusUp method. The Stylus Input thread is backgroud thread. As we all know, any exception thrown in a background thread will destroy the application. We are hard to catch the background thread and recover this thread. Though we can use AppDomain.CurrentDomain.UnhandledException and add <legacyUnhandledExceptionPolicy enabled="1"/> to app.config to catch it.

The StylusPlugIn can be inherited and we can overwrite the method. And we can not stop our friend add his code in the method, such as OnStylusDown method. But we may not enough careful in our code that the code will throw the exception in unexpected in the OnStylusDown method. And the exception will break the stylus input thread and the WPF application will stop responding the touch. And we can not do something to recover the touch responding. Just like this code. The code will break the Stylus Input thread.

public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
StylusPlugIns.Add(new Foo());
}
} public class Foo : StylusPlugIn
{
/// <inheritdoc />
protected override void OnStylusDown(RawStylusInput rawStylusInput)
{
throw new Exception();
}
}

The OnStylusDown running in Stylus Input thread and if some friend throws any exceptions that will break the thread. And the application will stop responding touch.

Of course, the actual situation may be more complicated. Maybe some of my friends just didn't realize that the code he wrote was unstable. But add try catch to all the method is an evil code.

But I do not think we can throw any unintended exceptions in StylusPlugIn.

See StylusPlugIn Class (System.Windows.Input.StylusPlugIns)

If you use a StylusPlugIn inside a control, you should test the plug-in and control extensively to make sure they do not throw any unintended exceptions.

See Intercepting Input from the Stylus

If a StylusPlugIn throws or causes an exception, the application will close. You should thoroughly test controls that consume a StylusPlugIn and only use a control if you are certain the StylusPlugIn will not throw an exception.

Just as the document say, we should make sure the code do not throw any unintended exceptions in StylusPlugIn. But actual we are hard to do it in the complex business.

I think it may be a good way that we can catch all the exceptions in the code that fire the StylusPlugIn method.

We are making a full-screen touch application and the user can only control the machine by touch input. If the WPF application stops responding touch, the user can not do something except reboot.

All the demo code in github

WPF will break when an exception be throw in the StylusPlugIn · Issue #1037 · dotnet/wpf

2019-10-7-WPF-will-break-when-an-exception-be-throw-in-the-StylusPlugIn的更多相关文章

  1. 2019.10 搜索引擎最新排名,Elasticsearch遥遥领先

    大数据的搜索平台已经成为了众多企业的标配,Elasticsearch.Splunk(商业上市公司).Solr(Apache开源项目)是其中最为优秀和流行的选择.在2019.10 最新搜索引擎排名中,E ...

  2. 【2019.10.17】十天Web前端程序员体验(软件工程实践第五次作业)

    结对信息.具体分工 Github地址:https://github.com/MokouTyan/131700101-031702425 学号 昵称 主要负责内容 博客地址 131700101 莫多 代 ...

  3. TIZ_c 第0周总结(2019/10/15-2019/10/22)工欲善其事必先利其器

    TIZ_c 第0周总结(2019/10/15-2019/10/22)工欲善其事必先利其器 任务清单 给自己取一个酷酷的id,并选择1-2个喜欢的方向.(只是初步选择,后期可更改) 改下群名片.例如yo ...

  4. WPF Set connectionId threw an exception异常 以及重复dll的问题

    1.DataOutputWPF 在显示norlib.Basic.UserConfigControl时 抛出异常 xmlparsingException : WPF Set connectionId t ...

  5. 2019.10.26 CSP%您赛第三场

    \(CSP\)凉心模拟^_^ --题源\(lqx.lhc\)等各位蒟蒻 题目名称 比赛 传递消息 开关灯 源文件名 \(competition.cpp\) \(message.cpp\) \(ligh ...

  6. 2019.10.18模拟赛T3

    题目大意: 求$\sum\limits_{i=1}^n\sum\limits_{j=1}^n[lcm(i,j)>n](n\leq 10^{10})$的值. 题解: 这题貌似有n多种做法... 为 ...

  7. 【2019.10.7 CCF-CSP-2019模拟赛 T3】未知的数组(unknown)(并查集+动态规划)

    预处理 考虑模数\(10\)是合数不好做,所以我们可以用一个常用套路: \(\prod_{i=l}^ra_i\equiv x(mod\ 10)\)的方案数等于\(\prod_{i=l}^ra_i\eq ...

  8. 【2019.10.7 CCF-CSP-2019模拟赛 T2】绝对值(abs)(线段树细节题)

    找规律 设\(p_i=a_{i+1}-a_i\),则答案就是\(\sum_{i=1}^{n-1}p_i\). 考虑若将\(a_i\)加上\(x\)(边界情况特殊考虑),就相当于是将\(p_{i-1}\ ...

  9. 牛客CSP-S提高组赛前集训营1———2019.10.29 18:30 至 22:00

    期望得分:100+0+10 实际得分:40+0+0 考炸了... T1:题目链接 究竟为什么会这样,,, 仔细研读我的丑代码 发现... 枯辽.... #include<cstdio> # ...

  10. Problem A. 最近公共祖先 ———2019.10.12

    我亲爱的学姐冒险跑去为我们送正解 但是,,,, 阿龙粗现了! cao,, 考场期望得分:20   实际得分:20 Problem A. 最近公共祖先 (commonants.c/cpp/pas) 最近 ...

随机推荐

  1. 记录--前端使用a链接下载内容增加loading效果

    这里给大家分享我在网上总结出来的一些知识,希望对大家有所帮助 问题描述:最近工作中出现一个需求,纯前端下载 Excel 数据,并且有的下载内容很多,这时需要给下载增加一个 loading 效果. 代码 ...

  2. verilog之readmemb

    verilog之readmemb 1.基本作用 用于读取存储器的值的系统函数.这里首先要知道什么是存储器.在verilog中,有一些比较大的数据是需要存储的,一般需要使用存储器,语法结构类似二维数组. ...

  3. KingbaseES V8R3集群运维案例之---流复制异步同步及全同步模式配置

    案例说明: 通过案例描述KingbaseES V8R3集群异步.同步及全同步强一致性配置,本案例为一主二备的架构. 适用版本: KingbaseES V8R3 集群架构: 集群复制配置参数说明: 1) ...

  4. KingbaseES 统计信息收集器没有响应问题分析

    统计信息收集器没有响应/Stats collector is not responding 问题现象: kingbase数据库日志提示:统计信息收集器没有响应/Stats collector is n ...

  5. Java开发岗面试题小结

    8种基本数据类型 类型名称 关键字 占用内存 取值范围 字节型 byte 1 字节 -128~127 短整型 short 2 字节 -32768~32767 整型 int 4 字节 -21474836 ...

  6. #分块,可撤销并查集#洛谷 5443 [APIO2019]桥梁

    题目 分析 最直接的做法就是在线一边修改边权,询问直接全部重排, 然后用可撤销并查集维护连通块大小,这样时间复杂度为 \(O(qm)\) 同样尽量让大部分的边不需要修改边权,那么每 \(B\) 个操作 ...

  7. 震撼!这个Python模块竟然能自动修复代码!

    说到Python的强大的地方,那真的是太多了,优雅.简洁.丰富且强大的第三方库.开发速度快,社区活跃度高等,所以才使得Python才会如此的受欢迎. 今天给大家介绍一个特别暴力的Python库: Fu ...

  8. 前端使用 Konva 实现可视化设计器(3)

    github/gitee Star 终于有几个了! 从这章开始,难度算是(或者说细节较多)升级,是不是值得更多的 Star 呢?! 继续求 Star ,希望大家多多一键三连,十分感谢大家的支持~ 创作 ...

  9. 【译】Visual Studio 中的 GitHub Copilot:2023年回顾

    在快速发展的软件开发世界中,保持领先是至关重要的.在 Visual Studio 中引入AI,特别是 GitHub Copilot,已经彻底改变了开发人员的编码方式.通过将 Copilot 集成到 V ...

  10. 开发案例:使用canvas实现图表系列之折线图

      一.功能结构 实现一个公共组件的时候,首先分析一下大概的实现结构以及开发思路,方便我们少走弯路,也可以使组件更加容易拓展,维护性更强.然后我会把功能逐个拆开来讲,这样大家才能学习到更详细的内容.下 ...