2017-01-23 7 views
3

これはProgramクラスである:私は私のフォームを閉じるには、「X」ボタンをクリックするとC#のWinFormsアプリdoesntの近く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"); 
     } 
    } 
} 

は今、これは私がして見るものです対

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). 

2015しかし、それからの出力はまだdoesntのアプリケーションを終了し、プロセスはまだ「赤の広場」としてVisual Studioで開いているように見える通称ボタンがまだ押されるのを待っている「デバッグを停止」。私はそれを押したとき、私は、次のメッセージが出ます:

The program '[8216] TestClosingApp.vshost.exe' has exited with code -1 (0xffffffff). 

を私は窓からのログオフを行い、問題が戻ってきた場合に興味深いことに消える、視覚的なスタジオを再起動すると、問題を解決していません。

+0

これは 'COMException'を上げる問題ではありません。これにより、アプリケーションが終了しなくなる可能性があります。あなたはその例外の起源を共有できますか? –

+0

は、フォームを閉じるコードを表示します –

+0

[この質問](http://stackoverflow.com/questions/4281425/how-to-avoid-a-system-runtime-interopservices-comexception)を見てください - それは流すかもしれませんなぜあなたはCOMExceptionを取得しているのか、そしてその発見方法 – Cullub

答えて

-3

使用MessageBox代わりConsole.WriteLine("I AM AT THE END OF THE MAIN");

MessageBox.Show("I AM AT THE END OF THE MAIN", "My message", MessageBoxButtons.OK, MessageBoxIcon.Warning); 
+0

可能です。デバッグ中に[出力ウィンドウ](https://msdn.microsoft.com/en-us/library/3hk6fby3.aspx)にメッセージが表示されます。 –

+0

もちろん、Console.WriteLineを呼び出すことができますが、出力はどこにも行きません。これは手元の問題とは何の関係もありません。 – poizan42

+0

私は間違った表現をしました。 –

関連する問題