捕获 Environment.Exit() 上的异常
我的 Main 函数结束后需要返回退出代码 1。 但是我有另一个线程永远不会结束(while(true))
。 所以我设法调用Environment.Exit(1)。 但是在处理 com 对象时我遇到了一些异常...
由于多种原因,我无法更改其他线程代码。 你们主张做什么?
我可以捕获来自 com 对象处理的异常吗? 我还有其他返回退出代码的选择吗?
I need to return an exit code of 1 after my Main functions ends. However I have an other thread that never ends (while(true))
. So I managed to call Environment.Exit(1). But I got some exception when disposing com objects...
For several reasons I can't change the other thread code. What do you guys advocate to do?
May I catch the exception coming from the com object disposing? Do I have an other option for returning an exit code?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我建议您:附加到 ProcessExit 事件以进行最后一次清理,或者...在线程上执行 Thread.Abort 以允许其在退出之前完成。
I suggest you to: attach to ProcessExit event to do any last chance cleanup or... do a Thread.Abort on the thread to allow it to finish before exit.
尝试使用:
但是; 如果另一个线程不是后台线程,您将需要它退出才能结束进程(在进程退出之前退出代码毫无意义)。
Try using:
However; if the other thread is not a background thread, you will need it to exit in order to end the process (the exit code is meaningless until the process exits).
您可以通过编写此代码来终止进程
Dim myProcess As System.Diagnostics.Process = System.Diagnostics.Process.GetCurrentProcess() myProcess.Kill()
或
环境.退出(1)
是终止所有进程的最佳方法
http://www.zhakkas.com/affiliates /idevaffiliate.php?id=542
you can kill proccess by writting this code
Dim myProcess As System.Diagnostics.Process = System.Diagnostics.Process.GetCurrentProcess() myProcess.Kill()
or
Environment.exit(1)
is best method for kill all processes
http://www.zhakkas.com/affiliates/idevaffiliate.php?id=542