停止在C#中调试事件
当应用程序关闭时,如何或在何处运行命令,即使是调试停止?
我需要在任何出口执行命令,即使用户是开发人员并单击Visual Studio上的“停止调试”按钮。
我尝试着
Application.ApplicationExit += new EventHandler(this.OnApplicationExit);
但它不起作用。 也许我错了或不是活动。
我正在使用Winforms而不是,在Form Close上不能成为事件。
我正在使用Visual Studio 2005 Net Framework 2.0(按客户端要求),但仅供参考。
也许我可以改写这个吗?:
public static void Exit();
问题是“停止调试”function将完全停止应用程序 – 因此该应用程序中的代码将不再运行。
实现这一目标的唯一方法是观察外部调试过程并在代码停止时执行代码。
根据[MSDN]:
如果程序是从Visual Studio启动的,则Stop Debugging将终止正在调试的进程。
但是,您可以使用visual studio插件实现所需的function 。
试试这个:
using System; using System.Collections.Generic; using System.Linq; using System.Windows.Forms; namespace Prueba { static class Program { [STAThread] static void Main() { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.Run(new Form1()); //This is the magic line code :P AppDomain.CurrentDomain.ProcessExit += new EventHandler(CurrentDomain_ProcessExit); } static void CurrentDomain_ProcessExit(object sender, EventArgs e) { MessageBox.Show(""); } } }
引用在这里(FredrikMörk):. NET控制台应用程序退出事件
根据MSDN: http : //msdn.microsoft.com/en-us/library/system.windows.forms.application.applicationexit%28v=vs.80%29.aspx
// Handle the ApplicationExit event to know when the application is exiting. Application.ApplicationExit += new EventHandler(this.OnApplicationExit); private void OnApplicationExit(object sender, EventArgs e) { // When the application is exiting }
这是你实施的吗?
上述就是C#学习教程:停止在C#中调试事件分享的全部内容,如果对大家有所用处且需要了解更多关于C#学习教程,希望大家多多关注—计算机技术网(www.ctvol.com)!
本文来自网络收集,不代表计算机技术网立场,如涉及侵权请联系管理员删除。
ctvol管理联系方式QQ:251552304
本文章地址:https://www.ctvol.com/cdevelopment/1013379.html