I have a VSTO addin that displays a a dialog box with buttons yes no and cancel. I want the form to close anytime cancel or the X are clicked. I also want the application to quit when the form is closed. Here is my code:
var frm = new Form1();
DialogResult res = frm.ShowDialog();
if (client != null)
{
if (res == DialogResult.Yes)
{
path = DRIVE_LETTER + ":/Clients/" + client + "/Correspondence/";
}
else if (res == DialogResult.No)
{
path = DRIVE_LETTER + ":/Clients Project History/" + client + "/Correspondence/";
}
else if (res == DialogResult.Cancel)
{
frm.Close();
}
else
{
frm.Close();
}
And then my form closing event handler:
private void Form1_Closing(object sender, CancelEventArgs e)
{
Application.Exit();
}
But it doesn't seem to work. Microsoft.Office.Interop.Outlook.Application doesn't have an Exit method. How can I do the equivalent from within VSTO? I want my application to stop executing completely when those forms are canceled/closed.
Thanks
EDIT: can anyone provide an example of quitting the addin. Or stopping all execution if a certain condition is met, like Pyton's sys.exit(). I don't want outlook to close, just the addin to stop execution. Not even unload, just stop.