About Retrieving Values in System.IO.DriveInfo

Asked 2 years ago, Updated 2 years ago, 41 views

When I write code in Windows C#, I don't understand the following:

System.IO.DriveInfo=newSystem.IO.DriveInfo("Z");
if(drive.IsReady)
{
strings;
s=string.Format ("{0:f1}GB/{1:f1}GB", drive.TotalFreeSpace/1024/1024/1024, drive.TotalSize/1024/1024/1024);
//  hereinafter abbreviated
}

Do this every second

c# windows

2022-09-30 18:39

2 Answers

Is there a way to find out how you're actually getting the value?

Implementation of System.IO.DriveInfo can be found at driveinfo.cs.
TotalFreeSpace and TotalSize appear to be specifications for the Windows API GetDiskFreeSpaceEx.

How GetDiskFreeSpaceEx gets the information was not known from the API documentation.Contact Microsoft Support for more information.


2022-09-30 18:39

Is there anything else I can do other than get it every second?

What's the purpose of getting it? USB memory or SD card removal detection?Network drive disconnection detection?Check disk space?Depending on that, I may be able to make another suggestion.

Checking the capacity of the connected USB memory every second means that the Safely Removed menu is not satisfactory, and it is the worst on the UX side.I don't think Oira would ever write a code like this.

If you want to detect the attachment and detachment of the drive name itself, simply handle the WM_DEVICECHANGE and get the drive information.
http://d.hatena.ne.jp/ohyajapan/20081123/p1

CD/DVD/BLURAY media may have been removed from the drive WM_DEVICECHANGE is available
https://support.microsoft.com/ja-jp/help/163503/how-to-receive-notification-of-cd-rom-insertion-or-removal

"Other than that, if you add ""why, what do you want to do"" in editing the original question, you may get a different answer."


2022-09-30 18:39

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.