This is the Program class:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace TestClosingApp
{
static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
Console.WriteLine("I AM AT THE END OF THE MAIN");
}
}
}
now when i click the "X" button to close my form, this is what i see in the output from vs 2015
I AM AT THE END OF THE MAIN
Exception thrown: 'System.Runtime.InteropServices.COMException' in System.Windows.Forms.dll
The thread 0x1c34 has exited with code 0 (0x0).
The thread 0x2008 has exited with code 0 (0x0).
But that still doesnt end the application, the process seem to still be open in visual studio as the "red square" aka "stop debugging" button is still waiting to be pressed. When i press it i get the following message:
The program '[8216] TestClosingApp.vshost.exe' has exited with code -1 (0xffffffff).
Interestingly if I do a logoff from windows and come back the problem goes away, restarting visual studio doesn't solve the problem.