BeginInvoke for Folder datagrid

auto-picks the correct thread for the control/form

batch editor progressbar is useless cuz the editor is so fast for 99.99% of uses (only really matters for processing a folder on slow drives), yay speed.
This commit is contained in:
Kurt 2024-04-26 01:34:47 -05:00
parent 3358038172
commit a296403595
3 changed files with 16 additions and 20 deletions

View file

@ -36,7 +36,7 @@ internal static class Program
new Task(() => splash.ShowDialog()).Start(); new Task(() => splash.ShowDialog()).Start();
new Task(() => EncounterEvent.RefreshMGDB(WinForms.Main.MGDatabasePath)).Start(); new Task(() => EncounterEvent.RefreshMGDB(WinForms.Main.MGDatabasePath)).Start();
var main = new Main(); var main = new Main();
splash.Invoke(splash.ForceClose); splash.BeginInvoke(splash.ForceClose);
Application.Run(main); Application.Run(main);
} }

View file

@ -204,22 +204,15 @@ public partial class BatchEditor : Form
} }
// Progress Bar // Progress Bar
private void SetupProgressBar(int count) private void SetupProgressBar(int count) => PB_Show.BeginInvoke(() =>
{ {
MethodInvoker mi = () => { PB_Show.Minimum = 0; PB_Show.Step = 1; PB_Show.Value = 0; PB_Show.Maximum = count; }; PB_Show.Minimum = 0;
if (PB_Show.InvokeRequired) PB_Show.Step = 1;
PB_Show.Invoke(mi); PB_Show.Value = 0;
else PB_Show.Maximum = count;
mi.Invoke(); });
}
private void SetProgressBar(int position) private void SetProgressBar(int position) => PB_Show.BeginInvoke(() => PB_Show.Value = position);
{
if (PB_Show.InvokeRequired)
PB_Show.Invoke((MethodInvoker)(() => PB_Show.Value = position));
else
PB_Show.Value = position;
}
private void ProcessSAV(IList<SlotCache> data, IReadOnlyList<StringInstruction> Filters, IReadOnlyList<StringInstruction> Instructions) private void ProcessSAV(IList<SlotCache> data, IReadOnlyList<StringInstruction> Filters, IReadOnlyList<StringInstruction> Instructions)
{ {
@ -239,7 +232,10 @@ public partial class BatchEditor : Form
var spec = pk.Species; var spec = pk.Species;
if (spec == 0 || spec > max) if (spec == 0 || spec > max)
{
b.ReportProgress(i);
continue; continue;
}
if (entry.Source is SlotInfoBox info && SAV.GetSlotFlags(info.Box, info.Slot).IsOverwriteProtected()) if (entry.Source is SlotInfoBox info && SAV.GetSlotFlags(info.Box, info.Slot).IsOverwriteProtected())
editor.AddSkipped(); editor.AddSkipped();

View file

@ -30,6 +30,8 @@ public partial class SAV_FolderList : Form
dgDataRecent.ContextMenuStrip = GetContextMenu(dgDataRecent); dgDataRecent.ContextMenuStrip = GetContextMenu(dgDataRecent);
dgDataBackup.ContextMenuStrip = GetContextMenu(dgDataBackup); dgDataBackup.ContextMenuStrip = GetContextMenu(dgDataBackup);
dgDataRecent.Sorted += (_, _) => GetFilterText(dgDataRecent);
dgDataBackup.Sorted += (_, _) => GetFilterText(dgDataBackup);
var extra = Paths.Select(z => z.Path).Where(z => z != Main.BackupPath).Distinct(); var extra = Paths.Select(z => z.Path).Where(z => z != Main.BackupPath).Distinct();
var backup = SaveFinder.GetSaveFiles(drives, false, [Main.BackupPath], false); var backup = SaveFinder.GetSaveFiles(drives, false, [Main.BackupPath], false);
@ -274,17 +276,15 @@ public partial class SAV_FolderList : Form
var sav = new SavePreview(next, Paths); var sav = new SavePreview(next, Paths);
void Load() => LoadEntry(dgData, list, sav); void Load() => LoadEntry(dgData, list, sav);
dgData.Invoke(Load); dgData.BeginInvoke(Load);
ctr++; ctr++;
if (ctr < 15 && ctr % 7 == 0) if (ctr < 15 && ctr % 7 == 0)
dgData.Invoke(RefreshResize); dgData.BeginInvoke(RefreshResize);
} }
dgData.Invoke(RefreshResize); dgData.BeginInvoke(RefreshResize);
enumerator.Dispose(); enumerator.Dispose();
}); });
dgData.Sorted += (_, _) => GetFilterText(dgData);
return list; return list;
} }