title: Thread.Abort and App crash
body: <p>all
  I found something wierd with my program</p>
  
  <pre class="lang-cs prettyprint-override"><code>using System;
  using System.Data.SqlTypes;
  using System.Threading;
  namespace TestCrash
  {
    class Program
    {
      static void Main(string[] args)
      {
        /*Console.WriteLine(typeof(SqlInt32));*/
        var h = new Holder();
        h.Test();
        Console.WriteLine("TestHolder");
        Console.ReadLine();
      }
    }
    public class Holder
    {
        private Thread t;
        private void Work()
        {
            Thread.Sleep(Timeout.Infinite);
        }
        ~Holder()
        {
            t.Abort();
        }
        public void Test()
        {
            t = new Thread(new ThreadStart(Work));
            t.IsBackground = true;
            t.Start();
        }
    }
  </code></pre>
  
  <p>This program terminates normally, however, if I <strong>uncomment the fisrt code line</strong> in Main which prints type of 'System.Data.SqlTypes.SqlInt32', the program will crash when exit, and the windows event tells me that 'Access Violation' (0xc0000005)</p>
  
  <pre><code>Faulting application name: TestCrash.exe, version: 1.0.0.0, time stamp: 0x52b0189a
  Faulting module name: ntdll.dll, version: 6.1.7600.16385, time stamp: 0x4a5be02b
  Exception code: 0xc0000005
  Fault offset: 0x00000000000159ad
  Faulting process id: 0x1f20
  Faulting application start time: 0x01cefb129f0bf5e8
  Faulting application path: C:\yuanf\Flx\Source\TestCrash\bin\Debug\TestCrash.exe
  Faulting module path: C:\Windows\SYSTEM32\ntdll.dll
  Report Id: ddf78d96-6705-11e3-bafd-005056b80090
  </code></pre>
  
  <p>I found it has something to do with the thread abort, but can anyone explain why abort the 'Work' thread in the finalizer will cause the crash, while in other threads this will work well?</p>
  
  <p>After some experiments, I found instead of printing 'System.Data.SqlTypes.SqlInt32', any code that can introduce loading of the System.Data.dll will make this program terminate abnormally. How does it matter?</p>
  
  <p><strong>To be noted, according to my tests, the crash happens only with .NET 4.0 on windows 2008R2, or win 7. With other version of .NET like 3.5 or 4.5, or OS like Windows XP, it terminates normally.</strong></p>
  
  <p>Thank you in advance!</p>