Improve async practices
MODIFY
WalletWasabi.Gui/Controls/WalletExplorer/HistoryTabViewModel.cs
WalletWasabi.Gui/Controls/WalletExplorer/HistoryTabViewModel.cs
@@ -30,8 +30,6 @@ namespace WalletWasabi.Gui.Controls.WalletExplorer
{
Transactions = new ObservableCollection<TransactionViewModel>();
- RewriteTableAsync().GetAwaiter();
-
this.WhenAnyValue(x => x.SelectedTransaction).Subscribe(async transaction =>
{
if (Global.UiConfig.Autocopy is false || transaction is null)
@@ -45,6 +43,8 @@ namespace WalletWasabi.Gui.Controls.WalletExplorer
SortCommand = ReactiveCommand.Create(() => RefreshOrdering());
DateSortDirection = SortOrder.Decreasing;
+
+ _ = TryRewriteTableAsync();
}
public override void OnOpen()
@@ -63,7 +63,7 @@ namespace WalletWasabi.Gui.Controls.WalletExplorer
.Merge(Observable.FromEventPattern(Global.WalletService, nameof(Global.WalletService.CoinSpentOrSpenderConfirmed)))
.Throttle(TimeSpan.FromSeconds(5))
.ObserveOn(RxApp.MainThreadScheduler)
- .Subscribe(async _ => await RewriteTableAsync())
+ .Subscribe(async _ => await TryRewriteTableAsync())
.DisposeWith(Disposables);
Global.UiConfig.WhenAnyValue(x => x.LurkingWifeMode).ObserveOn(RxApp.MainThreadScheduler).Subscribe(x =>
@@ -83,7 +83,7 @@ namespace WalletWasabi.Gui.Controls.WalletExplorer
return base.OnClose();
}
- private async Task RewriteTableAsync()
+ private async Task TryRewriteTableAsync()
{
try
{

MODIFY
WalletWasabi.Gui/ViewModels/StatusBarViewModel.cs
WalletWasabi.Gui/ViewModels/StatusBarViewModel.cs
@@ -283,7 +283,7 @@ namespace WalletWasabi.Gui.ViewModels
if (osDesc.Contains("16.04.1-Ubuntu", StringComparison.InvariantCultureIgnoreCase)
|| osDesc.Contains("16.04.0-Ubuntu", StringComparison.InvariantCultureIgnoreCase))
{
- MainWindowViewModel.Instance.ShowDialogAsync(new GenSocksServFailDialogViewModel()).GetAwaiter();
+ MainWindowViewModel.Instance.ShowDialogAsync(new GenSocksServFailDialogViewModel()).GetAwaiter().GetResult();
}
}
}

MODIFY
WalletWasabi.Packager/Program.cs
WalletWasabi.Packager/Program.cs
@@ -134,29 +134,29 @@ namespace WalletWasabi.Packager
private static void CreateDigests()
{
var tempDir = "DigestTempDir";
- IoHelpers.DeleteRecursivelyWithMagicDustAsync(tempDir).GetAwaiter();
+ IoHelpers.DeleteRecursivelyWithMagicDustAsync(tempDir).GetAwaiter().GetResult();
Directory.CreateDirectory(tempDir);
var torDaemonsDir = Path.Combine(LibraryProjectDirectory, "TorDaemons");
string torWinZip = Path.Combine(torDaemonsDir, "tor-win32.zip");
- IoHelpers.BetterExtractZipToDirectoryAsync(torWinZip, tempDir).GetAwaiter();
+ IoHelpers.BetterExtractZipToDirectoryAsync(torWinZip, tempDir).GetAwaiter().GetResult();
File.Move(Path.Combine(tempDir, "Tor", "tor.exe"), Path.Combine(tempDir, "TorWin"));
string torLinuxZip = Path.Combine(torDaemonsDir, "tor-linux64.zip");
- IoHelpers.BetterExtractZipToDirectoryAsync(torLinuxZip, tempDir).GetAwaiter();
+ IoHelpers.BetterExtractZipToDirectoryAsync(torLinuxZip, tempDir).GetAwaiter().GetResult();
File.Move(Path.Combine(tempDir, "Tor", "tor"), Path.Combine(tempDir, "TorLin"));
string torOsxZip = Path.Combine(torDaemonsDir, "tor-osx64.zip");
- IoHelpers.BetterExtractZipToDirectoryAsync(torOsxZip, tempDir).GetAwaiter();
+ IoHelpers.BetterExtractZipToDirectoryAsync(torOsxZip, tempDir).GetAwaiter().GetResult();
File.Move(Path.Combine(tempDir, "Tor", "tor"), Path.Combine(tempDir, "TorOsx"));
string hwiSoftwareDir = Path.Combine(LibraryProjectDirectory, "Hwi", "Software");
string hwiLinuxZip = Path.Combine(hwiSoftwareDir, "hwi-linux64.zip");
- IoHelpers.BetterExtractZipToDirectoryAsync(hwiLinuxZip, tempDir).GetAwaiter();
+ IoHelpers.BetterExtractZipToDirectoryAsync(hwiLinuxZip, tempDir).GetAwaiter().GetResult();
File.Move(Path.Combine(tempDir, "hwi"), Path.Combine(tempDir, "HwiLin"));
string hwiOsxZip = Path.Combine(hwiSoftwareDir, "hwi-osx64.zip");
- IoHelpers.BetterExtractZipToDirectoryAsync(hwiOsxZip, tempDir).GetAwaiter();
+ IoHelpers.BetterExtractZipToDirectoryAsync(hwiOsxZip, tempDir).GetAwaiter().GetResult();
File.Move(Path.Combine(tempDir, "hwi"), Path.Combine(tempDir, "HwiOsx"));
var tempDirInfo = new DirectoryInfo(tempDir);
@@ -169,7 +169,7 @@ namespace WalletWasabi.Packager
Console.WriteLine($"{file.Name} : {hash}");
}
- IoHelpers.DeleteRecursivelyWithMagicDustAsync(tempDir).GetAwaiter();
+ IoHelpers.DeleteRecursivelyWithMagicDustAsync(tempDir).GetAwaiter().GetResult();
}
private static void ReportStatus()
@@ -301,7 +301,7 @@ namespace WalletWasabi.Packager
process.WaitForExit();
}
- IoHelpers.DeleteRecursivelyWithMagicDustAsync(publishedFolder).GetAwaiter();
+ IoHelpers.DeleteRecursivelyWithMagicDustAsync(publishedFolder).GetAwaiter().GetResult();
Console.WriteLine($"Deleted {publishedFolder}");
}
}
@@ -341,7 +341,7 @@ namespace WalletWasabi.Packager
{
if (Directory.Exists(BinDistDirectory))
{
- IoHelpers.DeleteRecursivelyWithMagicDustAsync(BinDistDirectory).GetAwaiter();
+ IoHelpers.DeleteRecursivelyWithMagicDustAsync(BinDistDirectory).GetAwaiter().GetResult();
Console.WriteLine($"Deleted {BinDistDirectory}");
}
@@ -371,12 +371,12 @@ namespace WalletWasabi.Packager
var libraryBinReleaseDirectory = Path.GetFullPath(Path.Combine(LibraryProjectDirectory, "bin\\Release"));
if (Directory.Exists(guiBinReleaseDirectory))
{
- IoHelpers.DeleteRecursivelyWithMagicDustAsync(guiBinReleaseDirectory).GetAwaiter();
+ IoHelpers.DeleteRecursivelyWithMagicDustAsync(guiBinReleaseDirectory).GetAwaiter().GetResult();
Console.WriteLine($"Deleted {guiBinReleaseDirectory}");
}
if (Directory.Exists(libraryBinReleaseDirectory))
{
- IoHelpers.DeleteRecursivelyWithMagicDustAsync(libraryBinReleaseDirectory).GetAwaiter();
+ IoHelpers.DeleteRecursivelyWithMagicDustAsync(libraryBinReleaseDirectory).GetAwaiter().GetResult();
Console.WriteLine($"Deleted {libraryBinReleaseDirectory}");
}
@@ -475,7 +475,7 @@ namespace WalletWasabi.Packager
{
if (!dir.Name.Contains(toNotremove, StringComparison.OrdinalIgnoreCase))
{
- IoHelpers.DeleteRecursivelyWithMagicDustAsync(dir.FullName).GetAwaiter();
+ IoHelpers.DeleteRecursivelyWithMagicDustAsync(dir.FullName).GetAwaiter().GetResult();
}
}
@@ -654,10 +654,10 @@ namespace WalletWasabi.Packager
process.WaitForExit();
}
- IoHelpers.DeleteRecursivelyWithMagicDustAsync(publishedFolder).GetAwaiter();
+ IoHelpers.DeleteRecursivelyWithMagicDustAsync(publishedFolder).GetAwaiter().GetResult();
File.Delete(uncompressedDmgFilePath);
- IoHelpers.DeleteRecursivelyWithMagicDustAsync(publishedFolder).GetAwaiter();
+ IoHelpers.DeleteRecursivelyWithMagicDustAsync(publishedFolder).GetAwaiter().GetResult();
Console.WriteLine($"Deleted {publishedFolder}");
}
else if (target.StartsWith("linux"))
@@ -778,13 +778,13 @@ namespace WalletWasabi.Packager
process.WaitForExit();
}
- IoHelpers.DeleteRecursivelyWithMagicDustAsync(debFolderPath).GetAwaiter();
+ IoHelpers.DeleteRecursivelyWithMagicDustAsync(debFolderPath).GetAwaiter().GetResult();
string oldDeb = Path.Combine(BinDistDirectory, $"{ExecutableName}_{VersionPrefix}_amd64.deb");
string newDeb = Path.Combine(BinDistDirectory, $"Wasabi-{VersionPrefix}.deb");
File.Move(oldDeb, newDeb);
- IoHelpers.DeleteRecursivelyWithMagicDustAsync(publishedFolder).GetAwaiter();
+ IoHelpers.DeleteRecursivelyWithMagicDustAsync(publishedFolder).GetAwaiter().GetResult();
Console.WriteLine($"Deleted {publishedFolder}");
}
}

MODIFY
WalletWasabi/Models/ChaumianCoinJoin/CcjRound.cs
WalletWasabi/Models/ChaumianCoinJoin/CcjRound.cs
@@ -404,8 +404,9 @@ namespace WalletWasabi.Models.ChaumianCoinJoin
}
}
-#pragma warning disable CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed
- Task.Run(async () =>
+ _ = Task.Run(async () =>
+ {
+ try
{
TimeSpan timeout;
switch (expectedPhase)
@@ -456,7 +457,7 @@ namespace WalletWasabi.Models.ChaumianCoinJoin
}
// This will happen outside the lock.
- Task.Run(async () =>
+ _ = Task.Run(async () =>
{
try
{
@@ -520,8 +521,12 @@ namespace WalletWasabi.Models.ChaumianCoinJoin
}
});
}
+ }
+ catch (Exception ex)
+ {
+ Logger.LogWarning<CcjRound>($"Round ({RoundId}): {expectedPhase.ToString()} timeout failed with exception: {ex}");
+ }
});
-#pragma warning restore CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed
}
private Money CalculateNewDenomination()

MODIFY
WalletWasabi/Services/CcjClient.cs
WalletWasabi/Services/CcjClient.cs
@@ -103,13 +103,11 @@ namespace WalletWasabi.Services
Synchronizer.ResponseArrived += Synchronizer_ResponseArrivedAsync;
-#pragma warning disable CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed
var lastResponse = Synchronizer.LastResponse;
if (lastResponse != null)
{
- TryProcessStatusAsync(Synchronizer.LastResponse.CcjRoundStates);
+ _ = TryProcessStatusAsync(Synchronizer.LastResponse.CcjRoundStates);
}
-#pragma warning restore CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed
}
private async void Synchronizer_ResponseArrivedAsync(object sender, SynchronizeResponse e)

Improve async practices