Skip to content

Commit f331a17

Browse files
committed
Changed async loading again.
1 parent 2943f22 commit f331a17

File tree

2 files changed

+13
-30
lines changed

2 files changed

+13
-30
lines changed

Forms/MainForm.cs

Lines changed: 11 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -103,9 +103,10 @@ private async void MainForm_FormClosing(object sender, FormClosingEventArgs e)
103103
// and cancel all running tasks.
104104
if (loadSymbolsTask != null || updateProcessInformationsTask != null)
105105
{
106-
Hide();
107106
e.Cancel = true;
108107

108+
Hide();
109+
109110
if (loadSymbolsTask != null)
110111
{
111112
loadSymbolsTaskToken.Cancel();
@@ -452,21 +453,14 @@ private void MainForm_DragDrop(object sender, DragEventArgs e)
452453
}
453454
}
454455

455-
private async void processUpdateTimer_Tick(object sender, EventArgs e)
456+
private void processUpdateTimer_Tick(object sender, EventArgs e)
456457
{
457-
if (updateProcessInformationsTask == null || updateProcessInformationsTask.IsCompleted)
458+
if (updateProcessInformationsTask != null && !updateProcessInformationsTask.IsCompleted)
458459
{
459-
try
460-
{
461-
updateProcessInformationsTask = remoteProcess.UpdateProcessInformationsAsync();
462-
463-
await updateProcessInformationsTask;
464-
}
465-
catch
466-
{
467-
468-
}
460+
return;
469461
}
462+
463+
updateProcessInformationsTask = remoteProcess.UpdateProcessInformationsAsync();
470464
}
471465

472466
private void classesView_ClassSelected(object sender, ClassNode node)
@@ -652,7 +646,7 @@ private void LoadFileFromPath(string filePath, ref ReClassNetProject project)
652646
}
653647

654648
/// <summary>Loads all symbols for the current process and displays the progress status.</summary>
655-
private async void LoadAllSymbolsForCurrentProcess()
649+
private void LoadAllSymbolsForCurrentProcess()
656650
{
657651
if (loadSymbolsTask != null && !loadSymbolsTask.IsCompleted)
658652
{
@@ -671,18 +665,10 @@ private async void LoadAllSymbolsForCurrentProcess()
671665
);
672666

673667
loadSymbolsTaskToken = new CancellationTokenSource();
674-
loadSymbolsTask = remoteProcess.LoadAllSymbolsAsync(progress, loadSymbolsTaskToken.Token);
675-
676-
try
677-
{
678-
await loadSymbolsTask;
679-
}
680-
catch
681-
{
682-
683-
}
684668

685-
infoToolStripStatusLabel.Visible = false;
669+
loadSymbolsTask = remoteProcess
670+
.LoadAllSymbolsAsync(progress, loadSymbolsTaskToken.Token)
671+
.ContinueWith(_ => infoToolStripStatusLabel.Visible = false, TaskScheduler.FromCurrentSynchronizationContext());
686672
}
687673
}
688674
}

Memory/RemoteProcess.cs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -537,7 +537,7 @@ public Task LoadAllSymbolsAsync(IProgress<Tuple<Module, IEnumerable<Module>>> pr
537537
var copy = modules.ToList();
538538

539539
// Try to resolve all symbols in a background thread. This can take a long time because symbols are downloaded from the internet.
540-
// The COM objects used can only be used in the thread they are created so we can't use them...
540+
// The COM objects can only be used in the thread they were created so we can't use them.
541541
// Thats why an other task loads the real symbols afterwards in the UI thread context.
542542
return Task.Run(
543543
() =>
@@ -558,10 +558,7 @@ public Task LoadAllSymbolsAsync(IProgress<Tuple<Module, IEnumerable<Module>>> pr
558558
{
559559
foreach (var module in copy)
560560
{
561-
if (token.IsCancellationRequested)
562-
{
563-
break;
564-
}
561+
token.ThrowIfCancellationRequested();
565562

566563
try
567564
{

0 commit comments

Comments
 (0)