Run progress bar along with Disk Defragmentation in WPF

104 views Asked by At

I am developing a exe for hard disk defragmentation. For this I am using StartDefragmentation(String DeviceName) method of IDefragmenter Interface for defragmentation of hard disk particular drive.

It works properly, but I have to also run progress bar to display the status of defragmentation, but I don't know how much time it takes to complete the defragmentation of a particular drive. If I know the actual time take by next thread than i will easily set progress bar Value and Maximum property.

My Code :

private void StartDefragmentation()
{           
    try {
        private IDefragmenter Defragmenter;
        Defragmenter.StartDefragmentation("D:\\");
        //please call Background Thread for setting progressbar Value Counter and  Maximum property which is time taken by StartDefragmentation method
    } catch {
    }
}

I already use this code, but it didn't help me:

Stopwatch sw = Stopwatch.StartNew();

Defragmenter.StartDefragmentation(f);
sw.Stop();
Double timeTaken = sw.Elapsed.TotalMilliseconds;
0

There are 0 answers