1
using System;
using System.IO;
using System.Runtime.Serialization.Formatters.Binary;

namespace empty
{
    class Program
    {
        static Program()
        {
            AppDomain.CurrentDomain.ProcessExit += ExitHandler;
        }
        static void Main(string[] args)
        {
        }
        static void ExitHandler(object o, EventArgs args)
        {
            using (FileStream fs = new FileStream("file.bin", FileMode.Create))
            {
                BinaryFormatter bf = new BinaryFormatter();
                bf.Serialize(fs, new double[30000000]);         
            }
            using (FileStream fs = new FileStream("file.bin", FileMode.Create))
            {
                BinaryFormatter bf = new BinaryFormatter();
                bf.Serialize(fs, new double[30000000]);
            }
            Console.WriteLine("end");
        }
    }
}

出力が得られることを期待しています: "end" しかし、何も得られません。私は何を間違っていますか?

1回の連載ではそのような動作は起こらないので、意図的に2回の連載を使用しています。

4

1 に答える 1

6

If you look at the documentation for ProcessExit, you'll find this:

The total execution time of all ProcessExit event handlers is limited, just as the total execution time of all finalizers is limited at process shutdown. The default is two seconds.

So, if whatever action you're doing in that handler takes more than two seconds, it's not going to execute completely. This seems to be exactly the problem you're having.

于 2012-09-09T18:49:08.213 に答える