问题描述:

It is possible to capture on close or on error and run the code that we want.

However still i am at the developing phase and will be a lot more time, i am running application as debugging mode (clicking F5 button)

And also terminating application with stop debugging (shift F5)

When i terminate application with stop debugging the on close events are not firing (the ones that fire when you close application with clicking X mark on right top)

So are there any way to make application run on stop debugging button click ?

Here below my on close function - inside MainWindow.xaml.cs

AppDomain currentDomain = AppDomain.CurrentDomain;

Closing += new CancelEventHandler(CloseCrashHandlers.CloseHander);

Thank you very much for answers

Visual Studio 2013 V3

网友答案:

The only way to execute some custom code (or to 'make an application run' as you state in your question) when you hit the shift+F5 combination to stop debugging an application running under debugger is to create a Visual Studio extension (or addin) that hooks next visual studio extensibility event:

EnvDTE.DebuggerEvents _dteDebuggerEvents;

_dteDebuggerEvents = VsObject.DTE.Events.DebuggerEvents;

_dteDebuggerEvents.OnEnterDesignMode += _dteDebuggerEvents_OnEnterDesignMode;
_dteDebuggerEvents.OnContextChanged += _dteDebuggerEvents_OnContextChanged;


void _dteDebuggerEvents_OnEnterDesignMode(dbgEventReason Reason)
{
   switch (Reason)
   {
       case dbgEventReason.dbgEventReasonStopDebugging:
             // do whatever you need here
       break;
   }
}

Note: You won't be able to execute any code from your own running app using above handler.

相关阅读:
Top