Domanda

Ciao ho il codice di test seguente:

class Program
{
    static void Main(string[] args)
    {
        Thread t = new Thread(Work);
        t.Start();
        Thread.Sleep(1000);
        t.Abort();
        Thread.Sleep(1000);
        t.Abort();
        Thread.Sleep(1000);
        t.Abort();
        t.Join();
        Console.WriteLine("End");
    }

    static void Work()
    {
        int i = 0;
        while (i<10)
        {
            try
            {
                while(true);
            }
            catch(ThreadAbortException)
            {
                Thread.ResetAbort();
            }

            Console.WriteLine("I will come back!");
            i++;
        }
    }
}

Ogni volta, quando c'è un aborte, thread.resetabort () verrà eseguito. Mi chiedo cosa faccia questo resetbort. Perché quando lo eseguo, ho visto il seguente output: tornerò! Tornerò! Tornerò! E non ho visto l'output "fine" - sembra che questo programma non sia finito affatto. Sai perché? Grazie!

Nessuna soluzione corretta

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top