如何计算fileStream.SetLength的进度? [英] How to calculate progress for fileStream.SetLength?

查看:76
本文介绍了如何计算fileStream.SetLength的进度?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何计算fileStream.SetLength的进度?
我需要它,因为我在FlashDrive上使用它会花费一些时间.

How to calculate progress for fileStream.SetLength?
I need it, because i use it on a FlashDrive and it takes a time.

推荐答案


这是您最近提出的问题的后续内容.

http://www.codeproject. com/answers/70212/How-to-reserve-space-for-a-file-like-Explorer-does.aspx [
Hi,
This is a follow on from the question you asked recently.

http://www.codeproject.com/answers/70212/How-to-reserve-space-for-a-file-like-Explorer-does.aspx[^]

You have probably found out from your own experiments that SetLength is physically clearing the allocated space on the drive and this does take time, in fact it takes exactly the same time as if you were to write a file of the same length. Getting progress reports is not possible as SetLength does not return until this process is complete.

One of the answers to your previous post suggested writing a file of the correct size and of course if you were to do this you would be able to generate progress reports giving percent completion.

You may be unaware that NTFS formatted drives have an optimisation which allows SetLength to return almost immediately, often within about 10ms, although the allocated space cannot actually have been cleared in that time.

My suggestion is
1) Detect the drive format (System.IO.DriveInfo)
2) If it''s NTFS use SetLength which will be very fast
3) For any other format, write a file of the desired length and generate you own progress reports.


Alan.


FileStream.SetLength设置文件流的长度,仅此而已.计算进度是什么意思?你想做什么.

-Saurabh
FileStream.SetLength sets the length of the file stream and that is all. What do you mean by calculate progress? What are you trying to do.

-Saurabh


这篇关于如何计算fileStream.SetLength的进度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆