File.Copy with opened stream not crashing. Know why?
- by Carlo
I have this code, I open a stream (without closing or disposing it), then I copy the file used by the stream, I thought I should get a "Process can't access file somefile.xml because it's being used by another process" exception, but I don't. Any idea why? Thanks! The code:
StreamWriter writer = new StreamWriter("C:\\somefile.xml");
writer.Write(string.Empty);
// I thought this should crash since a stream is using "C:\somefile.xml"
File.Copy("C:\\somefile.xml", "C:\\copy of somefile.xml", true);