Skip to content

Image is used by another process and not able to delete

Asked Jul 13, 2016, 12:47 PM EDT1 answer
Share
LinkedInX
I'm trying to delete image after deleting record from list in wpf C#. but it always throw exception that file is used by anohter process and not allow me to delete.
 
Code
   string appPath = Path.GetDirectoryName(System.AppDomain.CurrentDomain.BaseDirectory) + @"\screenshots\";

  string schemename = selectedStockObject.Name.ToString();
                objSchemeBLL = new SchemeBLL();
                Scheme objTemp = objSchemeBLL.getSchemebyName(schemename);
 
Code
   GC.Collect();
                        Thread.Sleep(20);
                        File.Delete(objTemp.ImgPath);

1 Answer

Know the answer? Post it. Somebody with the same question will find it here.

  • Suthish Nair
    0
    You need to check that the file is already in use before deletion. If not in use, then call delete method.
    0