Why is FileStream.Close () hanging for a long time?

I am creating a very large file using FileStream (0.1 - 100 GB):

 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 freezes for a long time. I put strm.Close() after the loop, and it seems like this is a point of interference (closing the file).

(note that I'm Flush() after each Write() )

Why is this and how to overcome it?

+4
source share
1 answer

My comment was right.

See Hans answer. The answer is here: fooobar.com/questions/256289 / ...

Flush(true) will immediately go to disk. Flush() will not.

+4
source

Source: https://habr.com/ru/post/1488049/


All Articles