這是程序類:C#WinForms應用程序犯規接近達成Program.Main()結束時
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");
}
}
}
現在,當我點擊「X」按鈕關閉我的形式,這是我在看從2015年VS
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).
但是,輸出仍然不結束該應用程序,過程似乎仍是在Visual Studio中的「紅方」開又名「停止調試」按鈕仍然在等待被按下。當我按下它,我得到以下信息:
The program '[8216] TestClosingApp.vshost.exe' has exited with code -1 (0xffffffff).
有趣的是,如果我這樣做從Windows註銷,然後回來的問題消失,重新啓動Visual Studio中沒有解決的問題。
這不是提高'COMException'問題。這可能會導致應用程序無法關閉。你能分享那個例外的起源嗎? –
顯示你的代碼,關閉表格 –
看看[這個問題](http://stackoverflow.com/questions/4281425/how-to-avoid-a-system-runtime-interopservices-comexception) - 它可能會脫落一些關於你爲什麼得到COMException的信息 - 以及如何找到它。 – Cullub