title: How to delete file and that file is used by another process using C#
body: <p>In my C# application I want to delete file in below scenario.</p>
  
  <ol>
  <li><p>OpenFileDialog and select any .jpg file.</p></li>
  <li><p>Display that file in PictureBox.</p></li>
  <li><p>Delete that file if needed.</p></li>
  </ol>
  
  <p>I already try while doing step 3 I set default Image to PictureBox just before delete but that is not work.</p>
  
  <p>How can I delete file? Please suggest me.</p>
  
  <pre><code> // Code for select file.
   private void btnSelet_Click(object sender, EventArgs e)
   {
          if (DialogResult.OK == openFileDialog1.ShowDialog())
          {
              txtFileName.Text = openFileDialog1.FileName;
              myPictureBox.Image = Image.FromFile(openFileDialog1.FileName);
          }
   }
  
   // Code for Delete file
   private void btnDelete_Click(object sender, EventArgs e)
   {
          try
          {
              //myPictureBox.Image = Image.FromFile(System.IO.Directory.GetCurrentDirectory() + @"\Images\defaultImage.jpg");
              System.IO.File.Delete(txtFileName.Text);
              MessageBox.Show("File Delete Sucessfully");
          }
          catch(Exception ex)
          {
              MessageBox.Show(ex.Message);
          }
   }
  </code></pre>