We may be accustomed to code below:
if(File.Exists(xxx))
{
//I am here
using(var streamReader = new StreamReader("xxx"))
{
...
}
}
Well, the potential problem is that, the file xxx may be deleted by another thread (or process) when the code reaches "//I am here". Thus, the using block will throw exception.
Anyway to avoid this? (I don't want to have an ugly try-catch around using.) Any pattern or common practice to solve this kind of 'thread/process safety' problem for an unmanaged resource?
Thanks,