Run media scan in a background thread in GUI.

This commit is contained in:
2019-04-21 01:28:47 +01:00
parent a71b2e6cb3
commit d31bd8117f
2 changed files with 34 additions and 16 deletions

View File

@@ -102,4 +102,11 @@ namespace DiscImageChef.Core
/// Shows an error message
/// </summary>
public delegate void ErrorMessageHandler(string text);
/// <summary>
/// Updates lists of time taken on scanning the specified number of blocks
/// </summary>
/// <param name="time">Time in milliseconds</param>
/// <param name="blocks">Number of blocks scanned</param>
public delegate void ScanTime(double time, uint blocks);
}

View File

@@ -31,6 +31,7 @@
// ****************************************************************************/
using System;
using System.Threading;
using DiscImageChef.CommonTypes;
using DiscImageChef.Core;
using DiscImageChef.Core.Devices.Scanning;
@@ -67,13 +68,17 @@ namespace DiscImageChef.Gui.Forms
scanner.Abort();
}
// TODO: Allow to save MHDD and ImgBurn log files
void OnBtnScanClick(object sender, EventArgs e)
{
btnStop.Visible = true;
btnScan.Visible = false;
btnCancel.Visible = false;
new Thread(DoWork).Start();
}
// TODO: Allow to save MHDD and ImgBurn log files
void DoWork()
{
if(devicePath.Length == 2 && devicePath[1] == ':' && devicePath[0] != '/' && char.IsLetter(devicePath[0]))
devicePath = "\\\\.\\" + char.ToUpper(devicePath[0]) + ':';
@@ -94,18 +99,21 @@ namespace DiscImageChef.Gui.Forms
scanner = new MediaScan(null, null, devicePath, dev);
ScanResults results = scanner.Scan();
lblTotalTime.Text = lblTotalTime.Text =
$"Took a total of {results.TotalTime} seconds ({results.ProcessingTime} processing commands).";
lblAvgSpeed.Text = $"Average speed: {results.AvgSpeed:F3} MiB/sec.";
lblMaxSpeed.Text = $"Fastest speed burst: {results.MaxSpeed:F3} MiB/sec.";
lblMinSpeed.Text = $"Slowest speed burst: {results.MinSpeed:F3} MiB/sec.";
lblA.Text = $"{results.A} sectors took less than 3 ms.";
lblB.Text = $"{results.B} sectors took less than 10 ms but more than 3 ms.";
lblC.Text = $"{results.C} sectors took less than 50 ms but more than 10 ms.";
lblD.Text = $"{results.D} sectors took less than 150 ms but more than 50 ms.";
lblE.Text = $"{results.E} sectors took less than 500 ms but more than 150 ms.";
lblF.Text = $"{results.F} sectors took more than 500 ms.";
lblUnreadableSectors.Text = $"{results.UnreadableSectors.Count} sectors could not be read.";
Application.Instance.Invoke(() =>
{
lblTotalTime.Text = lblTotalTime.Text =
$"Took a total of {results.TotalTime} seconds ({results.ProcessingTime} processing commands).";
lblAvgSpeed.Text = $"Average speed: {results.AvgSpeed:F3} MiB/sec.";
lblMaxSpeed.Text = $"Fastest speed burst: {results.MaxSpeed:F3} MiB/sec.";
lblMinSpeed.Text = $"Slowest speed burst: {results.MinSpeed:F3} MiB/sec.";
lblA.Text = $"{results.A} sectors took less than 3 ms.";
lblB.Text = $"{results.B} sectors took less than 10 ms but more than 3 ms.";
lblC.Text = $"{results.C} sectors took less than 50 ms but more than 10 ms.";
lblD.Text = $"{results.D} sectors took less than 150 ms but more than 50 ms.";
lblE.Text = $"{results.E} sectors took less than 500 ms but more than 150 ms.";
lblF.Text = $"{results.F} sectors took more than 500 ms.";
lblUnreadableSectors.Text = $"{results.UnreadableSectors.Count} sectors could not be read.";
});
// TODO: Show list of unreadable sectors
/*
@@ -127,9 +135,12 @@ namespace DiscImageChef.Gui.Forms
dev.Close();
btnStop.Visible = false;
btnScan.Visible = true;
btnCancel.Visible = true;
Application.Instance.Invoke(() =>
{
btnStop.Visible = false;
btnScan.Visible = true;
btnCancel.Visible = true;
});
}
#region XAML IDs