title: Deleting file held by another process when Task is cancelled
body: <p>I am having an issue when I create a file (an Sqlite Database) inside a long-running <code>Task</code> I cannot properly delete it if the task was cancelled. It throws an <code>IOException</code> about being used in another process, I assume the other process is the <code>Task</code>.</p>
  
  <p>It does properly delete if I don't cancel the task and let it complete.</p>
  
  <pre><code> var cancellationTokenSource = new CancellationTokenSource();
   var cancellationToken = cancellationTokenSource.Token;
  
   string dbFilePath = @"C:\test.db";
  
   Task.Factory.StartNew(() =&gt; 
       {
            PopulateDatabase(dbFilePath);
       }, cancellationToken).ContinueWith((result) =&gt;
       {
            GC.Collect();
            File.Delete(dbFilePath);   // &lt;--- Used in other process exception occurs here
       }, TaskScheduler.FromCurrentSynchronizationContext()  // Called from a GUI thread
   );
  
   cancellationTokenSource.Cancel(); // This occurs after the task is running
  
   // I use using blocks in here, so the proper dispose methods should be called.
   private void PopulateDatabase(string filePath) {
       using(var conn = new SQLiteConnection(@"Data Source="+filePath+";")) {
           // Do a bunch of work
       }
   }
  </code></pre>
  
  <p>I even tried to modify <code>PopulateDatabase</code> to take in the <code>CancellationToken</code> and exit gracefully, but the same error occurs.</p>
  
  <pre><code> private void PopulateDatabase(string filePath, CancellationToken cancelToken) {
       using(var conn = new SQLiteConnection(@"Data Source="+filePath+";")) {
           // Do a bunch of work
           while(true) {
               if (cancelToken.IsCancellationRequested)
               {
                    return; // I assume this calls the appropriate Dispose methods
               }
           }
       }
   }
  </code></pre>