File.Copy with opened stream not crashing. Know why?
Posted
by Carlo
on Stack Overflow
See other posts from Stack Overflow
or by Carlo
Published on 2010-03-19T21:55:46Z
Indexed on
2010/03/19
22:01 UTC
Read the original article
Hit count: 204
c#
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);
© Stack Overflow or respective owner