A useful function the DTE has a built in is to prompt the user to save any unsaved files. It is a good idea to make this call in when shutting down the DTE, for example in the disconnect method of the VstaDesignTimeIntegration class.
EnvDTE.vsPromptResult promptResult = this.dte.ItemOperations.PromptToSave;
Below is a modified VstaDesignTimeIntegration.Disconnect method from the ShapeAppMacroRecordingCSharp SDK sample with this call added. The prompt will appear whether or not the DTE is visible
internal void Disconnect()
{
//prompt the user to save any unsaved files
EnvDTE.vsPromptResult promptResult = this.dte.ItemOperations.PromptToSave;
this.isShuttingDown = true;
StopDebugging(true);
// Unload external process
try
{
if (this.macroAddInProcess != null)
{
this.macroAddInProcess.ShuttingDown -= MacroAddInProcessExiting;
this.macroAddInProcess.Shutdown();
this.macroAddInProcess = null;
}
}
catch (Exception ex)
{
// Swallow the exception. We don't want to crash if the process has already been destroyed.
System.Diagnostics.Debug.WriteLine(ex.ToString());
}
}

Posted
Jun 19 2009, 11:14 AM
by
Melody