Run progress bar along with Disk Defragmentation in WPF
<p>I am developing a exe for hard disk defragmentation. For this I am using  <code>StartDefragmentation(String DeviceName)</code> method of <code>IDefragmenter</code> Interface for defragmentation of hard disk particular drive.</p>

<p>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.</p>

<p>My Code :</p>

<pre><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 {
    }
}
</code></pre>

<p>I already use this code, but it didn't help me:</p>

<pre><code>Stopwatch sw = Stopwatch.StartNew();

Defragmenter.StartDefragmentation(f);
sw.Stop();
Double timeTaken = sw.Elapsed.TotalMilliseconds;
</code></pre>