I have created a folder on the path C:\Users\MYUSER\Desktop\TEST\.
I have the following code:
private const string DIR = @"C:\Users\MYUSER\Desktop\TEST\tmp";
static void Main(string[] args)
{
if (Directory.Exists(DIR))
Directory.Delete(DIR);
for (int i = 0; i < 100; i++)
{
var dinfo = Directory.CreateDirectory(DIR);
Directory.Delete(DIR);
}
Directory.CreateDirectory(DIR);
}
When I execute the code, most times it runs OK, and I can see that there is a folder tmp inside the folder TEST.
My issue is that some other times, Directory.CreateDirectory(DIR) does not create a directory at all. I even checked the DirectoryInfo it returns and its Exists property is false and Directory.CreateDirectory(DIR) will not work because the folder does not exist. Is there any explanation for this weird behavior?