title: Delete file which cannot delete because is used by another process
body: <p>I know you are going to tell me that this question is stupid but I really cannot find a solution to delete my file.</p>
  <p>In fact, I open a connection to an .add file (same style as SQL in a way) but afterwards I cannot delete it because it is used by another process which is the process of my application.</p>
  <p>While doing some research on the internet I was able to find the solution to kill the process however if I do this it stops my application. Then I also found the GC collect but it doesn't work : /</p>
  <p>There is my code :</p>
  <pre><code>        try
          {
              string idClient = &quot;parfilux&quot;;
              string tableName = &quot;ACT,ACF&quot;;
              string dataSourceDBF = &quot;C:/winbooks/data/parfilux&quot;;
              string path = dataSourceDBF ;
              string pathTemp = dataSourceDBF + &quot;/CopyTempWebService/&quot;;
  
              if (!Directory.Exists(pathTemp)) Directory.CreateDirectory(pathTemp);
  
  
              string addFile = path + &quot;/&quot; + idClient + &quot;.add&quot;;
              File.Copy(addFile, pathTemp + idClient.ToUpper() + &quot;.add&quot;);
              File.Copy(addFile.Replace(&quot;.add&quot;, &quot;.ai&quot;), pathTemp + &quot;/&quot; + idClient.ToUpper() + &quot;.ai&quot;);
              File.Copy(addFile.Replace(&quot;.add&quot;, &quot;.am&quot;), pathTemp + &quot;/&quot; + idClient.ToUpper() + &quot;.am&quot;);
  
              tableName = tableName.Replace(&quot; &quot;, &quot;&quot;);
              string[] tables = tableName.Split(',');
  
              string pathTable = null;
              foreach (string tab in tables)
              {
                  pathTable = path + &quot;/&quot; + idClient.ToUpper() + &quot;_&quot; + tab.ToUpper() + &quot;.dbf&quot;;
                  File.Copy(pathTable, pathTemp + idClient.ToUpper() + &quot;_&quot; + tab.ToUpper() + &quot;.dbf&quot;);
                  File.Copy(pathTable.Replace(&quot;.dbf&quot;, &quot;.cdx&quot;), pathTemp + idClient.ToUpper() + &quot;_&quot; + tab.ToUpper() + &quot;.cdx&quot;);
              }
  
              AdsConnection dbfCo;
              //dbfCo.Close();
              dbfCo = new AdsConnection(@&quot;data Source=&quot; + dataSourceDBF + &quot;/CopyTempWebService/&quot; + idClient + &quot;.add;User ID=admin;Password=;ServerType=Local;ReadOnly=true;pooling=true;TrimTrailingSpaces=true;ShowDeleted=TRUE;TableType=CDX;LockMode=COMPATIBLE&quot;);
  
              dbfCo.Open();
  
              //QueryDataDBF(tableName, idClient, false);
              dbfCo.Close();
              dbfCo.Dispose();
  
  
              //Process process = Process.GetCurrentProcess();
              //Console.WriteLine(process.MainModule);
              //process.Kill();
              //foreach(Process pro in process)
              //{
              //    Console.WriteLine(pro);
              //    if(pro.ProcessName == pathTemp + idClient.ToUpper() + &quot;.add&quot;)
              //    {
              //        pro.Kill();
              //    }
              //}
              
              //System.GC.Collect();
              //System.GC.WaitForPendingFinalizers();
              //File.Delete(pathTemp + idClient.ToUpper() + &quot;.add&quot;);
  
             Directory.Delete(dataSourceDBF + &quot;/CopyTempWebService&quot;, true);
          }
          catch (Exception ex)
          {
              Console.WriteLine(ex.Message);
          }
  </code></pre>
  <p>I open a connection to my .add with the Advantage Data Provider library.</p>
  <p>Do you have any idea to fix this problem ? thank you in advance ;)</p>