码迷,mamicode.com
首页 > Windows程序 > 详细

[WinForm] - 关闭应用时 "has stopped working" 之解决

时间:2017-11-12 11:02:50      阅读:529      评论:0      收藏:0      [点我收藏+]

标签:overflow   www   exception   info   ase   关闭   es2017   end   应用   

背景

关闭 WinForm 应用出现 "has stopped working" 错误。

技术分享

 

Windows 日志

Faulting application name: PcClient.exe, version: 1.0.0.0, time stamp: 0x5a076b99
Faulting module name: KERNELBASE.dll, version: 10.0.15063.674, time stamp: 0x6d16dd24
Exception code: 0xe0434352
Fault offset: 0x000eb872
Faulting process id: 0xef4
Faulting application start time: 0x01d35b341fea1746
Faulting application path: C:\Program Files (x86)\Test\PcClient.exe
Faulting module path: C:\Windows\System32\KERNELBASE.dll
Report Id: 4fe7aef6-abc3-424b-9e16-85a18bfdeb2e
Faulting package full name:
Faulting package-relative application ID:

 

错误写法

private void App_FormClosed(object sender, FormClosedEventArgs e)
{
    Environment.Exit(0);
}

 

正确写法

private void App_FormClosed(object sender, FormClosedEventArgs e)
{
    if (Application.MessageLoop)
    {
        Application.Exit();
    }
    else
    {
        Environment.Exit(1);
    }
}

 

参考资料

https://stackoverflow.com/a/12978034

文章来源

http://www.cnblogs.com/jinzesudawei/p/7820926.html

[WinForm] - 关闭应用时 "has stopped working" 之解决

标签:overflow   www   exception   info   ase   关闭   es2017   end   应用   

原文地址:http://www.cnblogs.com/jinzesudawei/p/7820926.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!