Apply better asyncvoid practices
MODIFY
WalletWasabi.Backend/Global.cs
WalletWasabi.Backend/Global.cs
@@ -83,9 +83,16 @@ namespace WalletWasabi.Backend
}
public static async void IndexBuilderService_NewBlockAsync(object sender, Block block)
+ {
+ try
{
await Coordinator.ProcessBlockAsync(block);
}
+ catch (Exception ex)
+ {
+ Logger.LogWarning(ex, nameof(Global));
+ }
+ }
private static async Task AssertRpcNodeFullyInitializedAsync()
{

MODIFY
WalletWasabi.Gui/Controls/ExtendedTextBox.cs
WalletWasabi.Gui/Controls/ExtendedTextBox.cs
@@ -8,6 +8,7 @@ using ReactiveUI;
using System;
using System.Reactive.Linq;
using Avalonia.Media;
+using System.Threading.Tasks;
namespace WalletWasabi.Gui.Controls
{
@@ -17,14 +18,14 @@ namespace WalletWasabi.Gui.Controls
public ExtendedTextBox()
{
- CopyCommand = ReactiveCommand.Create(() =>
+ CopyCommand = ReactiveCommand.Create(async () =>
{
- CopyAsync();
+ await CopyAsync();
});
- PasteCommand = ReactiveCommand.Create(() =>
+ PasteCommand = ReactiveCommand.Create(async () =>
{
- PasteAsync();
+ await PasteAsync();
});
this.GetObservable(IsReadOnlyProperty).Subscribe(isReadOnly =>
@@ -56,7 +57,7 @@ namespace WalletWasabi.Gui.Controls
private ReactiveCommand CopyCommand { get; }
private ReactiveCommand PasteCommand { get; }
- private async void PasteAsync()
+ private async Task PasteAsync()
{
var text = await ((IClipboard)AvaloniaLocator.Current.GetService(typeof(IClipboard))).GetTextAsync();
@@ -89,7 +90,7 @@ namespace WalletWasabi.Gui.Controls
return text.Substring(start, end - start);
}
- private async void CopyAsync()
+ private async Task CopyAsync()
{
var selection = GetSelection();

MODIFY
WalletWasabi.Gui/Controls/NoparaPasswordBox.cs
WalletWasabi.Gui/Controls/NoparaPasswordBox.cs
@@ -164,6 +164,8 @@ namespace WalletWasabi.Gui.Controls
}
protected override async void OnKeyDown(KeyEventArgs e)
+ {
+ try
{
if (e.Key == Key.Capital || e.Key == Key.CapsLock) //on windows capslock is Key.Capital
{
@@ -248,6 +250,11 @@ namespace WalletWasabi.Gui.Controls
}
PaintText();
}
+ catch (Exception ex)
+ {
+ Logging.Logger.LogWarning<NoparaPasswordBox>(ex);
+ }
+ }
protected override void OnTextInput(TextInputEventArgs e)
{

MODIFY
WalletWasabi.Gui/Controls/WalletExplorer/CoinJoinTabViewModel.cs
WalletWasabi.Gui/Controls/WalletExplorer/CoinJoinTabViewModel.cs
@@ -389,15 +389,19 @@ namespace WalletWasabi.Gui.Controls.WalletExplorer
}
}
-#pragma warning disable RECS0165 // Asynchronous methods should return a Task instead of void
-
private async void CoinsList_DequeueCoinsPressedAsync()
-#pragma warning restore RECS0165 // Asynchronous methods should return a Task instead of void
+ {
+ try
{
var selectedCoin = _coinsList?.SelectedCoin;
if (selectedCoin == null) return;
await DoDequeueAsync(new[] { selectedCoin });
}
+ catch (Exception ex)
+ {
+ Logger.LogWarning<CoinJoinTabViewModel>(ex);
+ }
+ }
public Money AmountQueued
{

MODIFY
WalletWasabi.Gui/Controls/WalletExplorer/SendTabViewModel.cs
WalletWasabi.Gui/Controls/WalletExplorer/SendTabViewModel.cs
@@ -591,15 +591,19 @@ namespace WalletWasabi.Gui.Controls.WalletExplorer
}
}
-#pragma warning disable RECS0165 // Asynchronous methods should return a Task instead of void
-
private async void CoinsList_DequeueCoinsPressedAsync()
-#pragma warning restore RECS0165 // Asynchronous methods should return a Task instead of void
+ {
+ try
{
var selectedCoin = _coinList?.SelectedCoin;
if (selectedCoin == null) return;
await DoDequeueAsync(new[] { selectedCoin });
}
+ catch (Exception ex)
+ {
+ Logging.Logger.LogWarning<SendTabViewModel>(ex);
+ }
+ }
private async Task DoDequeueAsync(IEnumerable<CoinViewModel> selectedCoins)
{

MODIFY
WalletWasabi.Gui/MainWindow.xaml.cs
WalletWasabi.Gui/MainWindow.xaml.cs
@@ -18,8 +18,6 @@ namespace WalletWasabi.Gui
{
public class MainWindow : MetroWindow
{
-
-
public MainWindow()
{
InitializeComponent();
@@ -45,6 +43,8 @@ namespace WalletWasabi.Gui
}
private async void MainWindow_ClosingAsync(object sender, CancelEventArgs e)
+ {
+ try
{
Global.UiConfig.WindowState = WindowState;
Global.UiConfig.Width = Width;
@@ -52,10 +52,18 @@ namespace WalletWasabi.Gui
await Global.UiConfig.ToFileAsync();
Logging.Logger.LogInfo<UiConfig>("UiConfig is saved.");
}
+ catch (Exception ex)
+ {
+ Logging.Logger.LogWarning<MainWindow>(ex);
+ }
+ }
#pragma warning disable IDE1006 // Naming Styles
+
private async void OnActivated(object sender, EventArgs e)
#pragma warning restore IDE1006 // Naming Styles
+ {
+ try
{
Activated -= OnActivated;
@@ -77,6 +85,11 @@ namespace WalletWasabi.Gui
}
DisplayWalletManager();
}
+ catch (Exception ex)
+ {
+ Logging.Logger.LogWarning<MainWindow>(ex);
+ }
+ }
private void DisplayWalletManager()
{

MODIFY
WalletWasabi/Services/CcjClient.cs
WalletWasabi/Services/CcjClient.cs
@@ -89,11 +89,18 @@ namespace WalletWasabi.Services
}
private async void Synchronizer_ResponseArrivedAsync(object sender, SynchronizeResponse e)
+ {
+ try
{
IEnumerable<CcjRunningRoundState> newRoundStates = e.CcjRoundStates;
await ProcessStatusAsync(newRoundStates);
}
+ catch (Exception ex)
+ {
+ Logger.LogWarning<CcjClient>(ex);
+ }
+ }
public void Start()
{

MODIFY
WalletWasabi/Services/CcjCoordinator.cs
WalletWasabi/Services/CcjCoordinator.cs
@@ -191,6 +191,8 @@ namespace WalletWasabi.Services
}
private async void Round_StatusChangedAsync(object sender, CcjRoundStatus status)
+ {
+ try
{
var round = sender as CcjRound;
@@ -277,6 +279,11 @@ namespace WalletWasabi.Services
await MakeSureTwoRunningRoundsAsync(feePerInputs, feePerOutputs);
}
}
+ catch (Exception ex)
+ {
+ Logger.LogWarning<CcjCoordinator>(ex);
+ }
+ }
public void AbortAllRoundsInInputRegistration(string loggingCategory, string reason)
{

MODIFY
WalletWasabi/Services/WalletService.cs
WalletWasabi/Services/WalletService.cs
@@ -147,7 +147,9 @@ namespace WalletWasabi.Services
private void Coins_CollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
{
+#pragma warning disable CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed
RefreshCoinsHistoriesAsync();
+#pragma warning restore CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed
}
private void MemPool_TransactionReceived(object sender, SmartTransaction tx)
@@ -156,6 +158,8 @@ namespace WalletWasabi.Services
}
private async void IndexDownloader_ReorgedAsync(object sender, FilterModel invalidFilter)
+ {
+ try
{
using (HandleFiltersLock.Lock())
using (WalletBlocksLock.Lock())
@@ -174,6 +178,11 @@ namespace WalletWasabi.Services
}
}
}
+ catch (Exception ex)
+ {
+ Logger.LogWarning<WalletService>(ex);
+ }
+ }
private void RemoveCoinRecursively(SmartCoin toRemove)
{
@@ -189,6 +198,8 @@ namespace WalletWasabi.Services
}
private async void IndexDownloader_NewFilterAsync(object sender, FilterModel filterModel)
+ {
+ try
{
using (HandleFiltersLock.Lock())
using (WalletBlocksLock.Lock())
@@ -206,6 +217,11 @@ namespace WalletWasabi.Services
MemPool?.TryPerformMempoolCleanupAsync(Nodes, CancellationToken.None);
}
}
+ catch (Exception ex)
+ {
+ Logger.LogWarning<WalletService>(ex);
+ }
+ }
public async Task InitializeAsync(CancellationToken cancel)
{
@@ -262,7 +278,9 @@ namespace WalletWasabi.Services
}
}
Coins.CollectionChanged += Coins_CollectionChanged;
+#pragma warning disable CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed
RefreshCoinsHistoriesAsync();
+#pragma warning restore CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed
}
private async Task ProcessFilterModelAsync(FilterModel filterModel, CancellationToken cancel)
@@ -1076,7 +1094,7 @@ namespace WalletWasabi.Services
private long _refreshCoinCalls;
- public async void RefreshCoinsHistoriesAsync()
+ public async Task RefreshCoinsHistoriesAsync()
{
try
{
@@ -1111,7 +1129,9 @@ namespace WalletWasabi.Services
if (Interlocked.Read(ref _refreshCoinCalls) == 2) //scheduled to rerun so we start the work again
{
Interlocked.Exchange(ref _refreshCoinCalls, 0);
+#pragma warning disable CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed
RefreshCoinsHistoriesAsync();
+#pragma warning restore CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed
}
if (Interlocked.Read(ref _refreshCoinCalls) == 1) //done with the job
{

Apply better asyncvoid practices