[WinForm] - 关闭应用时 "has stopped working" 之解决
背景
关闭 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