I'm developing a multi threaded application. I have somewhere in my code :
File.Delete(sidetapedata);
File.Move(sidetapedata2, sidetapedata); //sidetapedata and sidetapedata2 are two file paths that correspond to sidetapedata.txt and sidetaptdata2.txt in some directory.
The second line sometimes runs fine and other times, it throws an IOException
:
Cannot create a file when that file already exists.
There is one more thread that is accessing the sidetapedata
file but that one is only reading this file, no write operations. I am using locks to protect race conditions. Don't know why this is happening.
UPDATE : even when visual c# debugger shows me this exception, looking into the directory that contains these files, I see there is no sidetapedata.txt
file but there is a sidetapedata2.txt
file!
UPDATE2 : Also, this behavior only happens when sidetapedata.txt
and sidetapedata2.txt
are both blank