上海家具人才招聘网,小屯公园,经济学人中文
static void main(string[] args) { //写日志 //使用线程池 for (int i = 0; i < 1000; i++) { threadpool.queueuserworkitem(new waitcallback(receivemessage), i); } console.readkey(); } private static void receivemessage(object index) { thread.sleep(100); int b = 0; try { if (index.tostring() == "50") { console.writeline(100 / b); } else { console.writeline(index.tostring()); } } catch (exception) { console.writeline(index+":出错"); } }
以上是测试代码,结论如下:
1.线程池中的异常不做处理:会导致整个程序的闪退
2.针对异常代码添加异常处理机制:不影响其他线程的执行
如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复
Net Core Web Api项目与在NginX下发布的方法
asp.net core3.1 引用的元包dll版本兼容性问题解决方案
IdentityServer4实现.Net Core API接口权限认证(快速入门)
ASP.NET Core MVC通过IViewLocationExpander扩展视图搜索路径的实现
网友评论