2019-10-7-WPF-will-break-when-an-exception-be-throw-in-the-StylusPlugIn
| 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的更多相关文章
- 2019.10 搜索引擎最新排名,Elasticsearch遥遥领先
大数据的搜索平台已经成为了众多企业的标配,Elasticsearch.Splunk(商业上市公司).Solr(Apache开源项目)是其中最为优秀和流行的选择.在2019.10 最新搜索引擎排名中,E ...
- 【2019.10.17】十天Web前端程序员体验(软件工程实践第五次作业)
结对信息.具体分工 Github地址:https://github.com/MokouTyan/131700101-031702425 学号 昵称 主要负责内容 博客地址 131700101 莫多 代 ...
- TIZ_c 第0周总结(2019/10/15-2019/10/22)工欲善其事必先利其器
TIZ_c 第0周总结(2019/10/15-2019/10/22)工欲善其事必先利其器 任务清单 给自己取一个酷酷的id,并选择1-2个喜欢的方向.(只是初步选择,后期可更改) 改下群名片.例如yo ...
- WPF Set connectionId threw an exception异常 以及重复dll的问题
1.DataOutputWPF 在显示norlib.Basic.UserConfigControl时 抛出异常 xmlparsingException : WPF Set connectionId t ...
- 2019.10.26 CSP%您赛第三场
\(CSP\)凉心模拟^_^ --题源\(lqx.lhc\)等各位蒟蒻 题目名称 比赛 传递消息 开关灯 源文件名 \(competition.cpp\) \(message.cpp\) \(ligh ...
- 2019.10.18模拟赛T3
题目大意: 求$\sum\limits_{i=1}^n\sum\limits_{j=1}^n[lcm(i,j)>n](n\leq 10^{10})$的值. 题解: 这题貌似有n多种做法... 为 ...
- 【2019.10.7 CCF-CSP-2019模拟赛 T3】未知的数组(unknown)(并查集+动态规划)
预处理 考虑模数\(10\)是合数不好做,所以我们可以用一个常用套路: \(\prod_{i=l}^ra_i\equiv x(mod\ 10)\)的方案数等于\(\prod_{i=l}^ra_i\eq ...
- 【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}\ ...
- 牛客CSP-S提高组赛前集训营1———2019.10.29 18:30 至 22:00
期望得分:100+0+10 实际得分:40+0+0 考炸了... T1:题目链接 究竟为什么会这样,,, 仔细研读我的丑代码 发现... 枯辽.... #include<cstdio> # ...
- Problem A. 最近公共祖先 ———2019.10.12
我亲爱的学姐冒险跑去为我们送正解 但是,,,, 阿龙粗现了! cao,, 考场期望得分:20 实际得分:20 Problem A. 最近公共祖先 (commonants.c/cpp/pas) 最近 ...
随机推荐
- 记录--uni-app adb安卓wifi无线调试
这里给大家分享我在网上总结出来的一些知识,希望对大家有所帮助 方法一 adb connect连接调试 前提条件: 电脑已安装adb工具 手机和电脑连接的同一个WIFI CMD进入到adb工具所在目录, ...
- [MAUI]模仿哔哩哔哩的一键三连
@ 目录 创建弧形进度条 绘制弧 准备物料 创建气泡 创建手势 创建交互与动效 项目地址 哔哩哔哩(Bilibili)中用户可以通过长按点赞键同时完成点赞.投币.收藏对UP主表示支持,后UP主多用&q ...
- linux 检查是否安装过某软件包
1.rpm包安装的,可以用 rpm -qa 看到,如果要查找某软件包是否安装,用 rpm -qa | grep "软件或者包的名字" 2.以deb包安装的,可以用 dpkg -l ...
- Chrome浏览器安装离线插件Markdown Here
前言 近期刚开通了微信公众号,想在上面发表一些自己的文章,由于排版问题很浪费时间,公众号后台本身不支持Markdown语法,所以就需要利用Markdown Here插件使得公众号后台支持Markdow ...
- #轮廓线dp,模型转换#洛谷 3226 [HNOI2012]集合选数
题目 问有多少个集合 \(S\) 是 \([1,n]\) 的子集, 并且 \(\forall a,b\in S,a|b\),满足 \(\frac{b}{a}\neq \{2,3\}\) 分析 可以发现 ...
- 【分享汇总】AIoT 开源科技节暨 OpenHarmony 技术论坛(附链接)
在开源科技 OSTech 和环球资源联手举办的"AIoT 开源科技节暨 OpenHarmony 技术论坛"上,一众技术大咖.开源鸿蒙生态上下游厂商与开发者群体齐聚一堂,畅谈&quo ...
- Docker学习路线5:在 Docker 中实现数据持久化
Docker 可以运行隔离的容器,包括应用程序和其依赖项,与主机操作系统分离.默认情况下,容器是临时的,这意味着容器中存储的任何数据在终止后都将丢失.为了解决这个问题并在容器生命周期内保留数据,Doc ...
- 使用IDEA直接连接数据库报错:Server returns invalid timezone. Go to 'Advanced' tab and set 'serverTimezone' property manually.
错误详情:使用IDEA直接连接数据库报错:Server returns invalid timezone. Go to 'Advanced' tab and set 'serverTimezone' ...
- RabbitMQ 01 概述
什么是消息队列 进行大量的远程调用时,传统的Http方式容易造成阻塞,所以引入了消息队列的概念,即让消息排队,按照队列进行消费. 它能够将发送方发送的信息放入队列中,当新的消息入队时,会通知接收方进行 ...
- 直播预告丨Hello HarmonyOS进阶课程第四课——ArkUI动画开发
为了帮助初识HarmonyOS的开发者快速入门,我们曾推出Hello HarmonyOS系列课程,从最基础的配置IDE和创建Hello World开始,详细介绍HarmonyOS基础.开发环境搭建.I ...