简体   繁体   English

如何在停止调试器后启动清理方法?

[英]How can I launch clean up method after stopping debugger?

I have created a bunch of unit tests for my library which manipulate a certain .html file. 我为我的库创建了一堆单元测试,它们操作某个.html文件。 What I want to do is back up the file before the tests and then restore it when the tests are over. 我想要做的是在测试之前备份文件,然后在测试结束时恢复它。 I am using the AssemblyCleanup attribute for the restoration part, which works pretty well. 我正在使用AssemblyCleanup属性来恢复部分,这非常有效。 The only problem is that when I stop the debugger manually, the clean up code is not executed and my file is not restored... Any advice? 唯一的问题是,当我手动停止调试器时,不执行清理代码并且我的文件没有恢复...任何建议?

You can't handle process termination from the process being terminated. 您无法处理终止进程的进程终止。 Your only option is having another process which observes the terminated process. 您唯一的选择是使用另一个进程来观察已终止的进程。

Rearranging your code to do cleanup on startup would probably be a much easier option. 重新安排代码以在启动时进行清理可能是一个更容易的选择。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM