Apparently, you are opening a file in the Isolated Storage with multiple instances of your application at the same time and you try to delete the file. Well, there's your problem. You cannot delete the file if another instance of your application has the file opened.
Here's what you can do:
- Use a Mutex to do inter-process synchronization see MSDN and check with the other application instances if it is ok to delete the file.
- Only allow one instance of your application to be run (although you explcitly said you wanted multiple instances, you may want to reconsider)
- Use a seperate file for each application instance
Which solution to use depends on how your application works and what the file is used for.
EDIT: You cannot check if the file is open before deleting it since the file may be opened between checking and deleting by another application instance.
If(!FileIsOpen(path))
{
// here, another application may open the file
DeleteFile(path); // oops
}
What you can do is:
try
{
DeleteFile(path);
}
catch(IsolatedStorageException)
{
// do nothing; let the other instances try and delete the file.
}