Reputation: 9015
I'm creating a very big file using a FileStream
(0.1 - 100 GBytes):
using (var strm = File.OpenWrite(Destination)) {
while(someCondition) {
bfr = GetBuffer();
strm.Write(bfr.Data, 0, ChunkSizeInBytes);
strm.Flush();
ShowProgress();
}
}
When I get to the end of the using
statement, the thread hangs for a long time. I put a strm.Close()
after the loop, and it seems that this is the jamming point (the file closure).
(please note that I Flush()
after each Write()
)
Why is it and how to overcome it ?
Upvotes: 4
Views: 1540
Reputation: 65059
My comment was correct.
See Hans Passant's answer here: https://stackoverflow.com/a/4921728/1517578
Flush(true)
will flush out to disk immediately. Flush()
will not.
Upvotes: 4