当 Visual Studio 停止调试时,我真的不能清理吗? [英] Can I really not clean up when Visual Studio stops debugging?

查看:26
本文介绍了当 Visual Studio 停止调试时,我真的不能清理吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个控制台应用程序,它运行一些易变的硬件.如果我不能很好地与它分离,Windows 会在五分钟后蓝屏.我可以通过使用 SetConsoleCtrlHandler 来捕捉应用程序何时关闭.但是当我在 Visual Studio 中点击停止调试"时,它会跳过这个过程,只是残酷地杀死了程序.截至 2009 年,nobody 似乎有 解决方案针对此

I have a console application that runs some temperamental hardware. If I don't detach from it nicely, windows tends to bluescreen five minutes later. I can catch when the application is closed by using SetConsoleCtrlHandler. But when I hit 'stop debugging' in visual studio, it skips this process and just kills the program brutally. As of 2009 it appears nobody has a solution for this problem.

还是这样吗?如果我不小心按错了按钮,我真的必须忍受蓝屏吗?

Is this still the case? Do I really have to live with a bluescreen if I accidentally hit the wrong button?

推荐答案

杀死进程就是那个按钮的作用.如果你想让程序优雅地终止,你需要让它运行到完成.您可以使用调试器的继续"按钮,或者只是从进程中分离,然后以正常方式退出程序.或者,您可以使用调试器执行一些使程序自行退出的操作,例如设置控制主循环的完成"标志.

Killing the process is what that button is for. If you want the program to terminate gracefully, you need to let it run to completion. You can use the debugger's "continue" button, or just detach from the process, and then quit the program in the normal way. Or you can use the debugger to do something that makes the program quit itself, such as setting a "done" flag that controls a main loop.

您可以考虑将您的程序分成两部分:处理硬件特性并为控制台应用程序提供干净"界面的服务,以及与服务对话而不是直接与硬件对话的控制台应用程序.

You might consider splitting your program into two parts: a service that deals with the hardware's peculiarities and presents a "clean" interface to the console application, and the console application which talks to the service instead of directly to the hardware.

这篇关于当 Visual Studio 停止调试时,我真的不能清理吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆