private void btn_Olustur_Click(object sender, EventArgs e) //dosya oluştur click
    {
        string path = Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + @"\yenidosya.txt";
        StreamWriter dosya = File.CreateText(path);
        if (!File.Exists(path))
        {
            //StreamWriter dosya = File.CreateText(path);
            for (int i = 0; i < liste.Count; i++)
            {
                dosya.WriteLine(liste.ElementAt(i));
            }
            dosya.Close();
            MessageBox.Show("Dosya oluşturuldu.", "BASARILI!");
        }
        else
        {
            DialogResult dialogResult = MessageBox.Show("Aynı isimde dosya mevcuttur(yenidosya.txt), değiştirilsin mi?", "HATA!", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Information);
            //MessageBox.Show("Aynı isimde dosya mevcuttur. (yenidosya.txt)", "HATA!");
            if (dialogResult == DialogResult.Yes)
            {
                File.Delete(path);
                for (int i = 0; i < liste.Count; i++)
                {
                    dosya.WriteLine(liste.ElementAt(i));
                }
                dosya.Close();
                MessageBox.Show("Dosya oluşturuldu.", "BASARILI!");
            }
        }
    }
If the file exists I want to delete it. But it gives a thread fault. error string: File.Delete (path);
error message: The process cannot access file "path", because it is being used by another process.