2

ASP .Net および非 Web アプリケーションを使用するクラスがあり、アプリケーションの終了のファイナライズが必要です (アプリの終了時にクリーンアップ呼び出しを必要とする .Net Framework クラスを消費します)。ASP.Net の IIS で次のテスト コードを実行すると、IIS のリセット中であっても、AppDomain.CurrentDomain.ProcessExit が起動しません。Application_End が起動しても。

(注: テスト コード ビハインド ページは、静的コンストラクターを実行させる方法でクラスを参照します)

public class A
{
    static A()
    {
        AppDomain.CurrentDomain.ProcessExit += A_Dtor;
    }

    public static string Text { get { return "Content"; } }
    public string B() { return "B"; }

    static void A_Dtor(object sender, EventArgs e)
    {
        StreamWriter sw = new StreamWriter(File.OpenWrite(@"c:\everyone\A_Dtor.txt"));
        sw.Write("test");
        sw.Close();

        Debug.WriteLine("Firing A_Dtor");
    }
}

ASP.Net アプリケーションで AppDomain.CurrentDomain.ProcessExit が起動する条件はありますか?

4

0 に答える 0