Skip to content

Code Quality: Removed async void methods #12128

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/Files.App/BaseLayout.cs
Original file line number Diff line number Diff line change
Expand Up @@ -526,7 +526,7 @@ private void FolderSettings_GroupOptionPreferenceUpdated(object? sender, GroupOp
private void FolderSettings_GroupDirectionPreferenceUpdated(object? sender, SortDirection e)
=> GroupPreferenceUpdated();

private async void GroupPreferenceUpdated()
private async Task GroupPreferenceUpdated()
{
// Two or more of these running at the same time will cause a crash, so cancel the previous one before beginning
groupingCancellationToken?.Cancel();
Expand Down Expand Up @@ -1349,7 +1349,7 @@ public void ResetRenameDoubleClick()
tapDebounceTimer.Stop();
}

protected async void ValidateItemNameInputText(TextBox textBox, TextBoxBeforeTextChangingEventArgs args, Action<bool> showError)
protected async Task ValidateItemNameInputText(TextBox textBox, TextBoxBeforeTextChangingEventArgs args, Action<bool> showError)
{
if (FilesystemHelpers.ContainsRestrictedCharacters(args.NewText))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -772,7 +772,7 @@ await sourceMatch.Select(x => x.src).ToListAsync(),
}
}

private async void CancelOperation(object operationID)
private void CancelOperation(object operationID)
=> FileOperationsHelpers.TryCancelOperation((string)operationID);

private async Task<bool> RequestAdminOperation()
Expand Down
6 changes: 3 additions & 3 deletions src/Files.App/Filesystem/LibraryManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ public async Task<LibraryLocationItem> UpdateLibrary(string libraryPath, string
return (true, string.Empty);
}

public static async void ShowRestoreDefaultLibrariesDialog()
public static async Task ShowRestoreDefaultLibrariesDialog()
{
var dialog = new DynamicDialog(new DynamicDialogViewModel
{
Expand All @@ -323,7 +323,7 @@ public static async void ShowRestoreDefaultLibrariesDialog()
await dialog.ShowAsync();
}

public static async void ShowCreateNewLibraryDialog()
public static async Task ShowCreateNewLibraryDialog()
{
var inputText = new TextBox
{
Expand Down Expand Up @@ -388,7 +388,7 @@ public static async void ShowCreateNewLibraryDialog()
await dialog.ShowAsync();
}

private async void OnLibraryChanged(WatcherChangeTypes changeType, string oldPath, string newPath)
private void OnLibraryChanged(WatcherChangeTypes changeType, string oldPath, string newPath)
{
if (newPath is not null && (!newPath.ToLowerInvariant().EndsWith(ShellLibraryItem.EXTENSION, StringComparison.Ordinal) || !File.Exists(newPath)))
{
Expand Down
2 changes: 1 addition & 1 deletion src/Files.App/Helpers/FilePropertiesHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public static class FilePropertiesHelpers
private static readonly Lazy<string> logoPath = new(GetFilesLogoPath);
public static string LogoPath => logoPath.Value;

public static async void ShowProperties(IShellPage associatedInstance)
public static async Task ShowProperties(IShellPage associatedInstance)
{
var item = GetItem(associatedInstance);
await OpenPropertiesWindowAsync(item, associatedInstance);
Expand Down
3 changes: 2 additions & 1 deletion src/Files.App/Helpers/MenuFlyoutHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using Microsoft.UI.Xaml.Controls;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using System.Windows.Input;

namespace Files.App.Helpers
Expand Down Expand Up @@ -89,7 +90,7 @@ private static void OnIsVisiblePropertyChanged(DependencyObject d, DependencyPro

#endregion IsVisible

private static async void SetupItems(MenuFlyout menu)
private static async Task SetupItems(MenuFlyout menu)
{
if (menu is null || Windows.ApplicationModel.DesignMode.DesignModeEnabled)
{
Expand Down
2 changes: 1 addition & 1 deletion src/Files.App/Helpers/NavigationHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public static async Task OpenSelectedItems(IShellPage associatedInstance, bool o
}
}

public static async void OpenItemsWithExecutable(IShellPage associatedInstance, IEnumerable<IStorageItemWithPath> items, string executable)
public static async Task OpenItemsWithExecutable(IShellPage associatedInstance, IEnumerable<IStorageItemWithPath> items, string executable)
{
// Don't open files and folders inside recycle bin
if (associatedInstance.FilesystemViewModel.WorkingDirectory.StartsWith(CommonPaths.RecycleBinPath, StringComparison.Ordinal) ||
Expand Down
2 changes: 1 addition & 1 deletion src/Files.App/Helpers/ShellContextMenuHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ private static void LoadMenuFlyoutItem(IList<ContextMenuFlyoutItemViewModel> men
}
}

async void InvokeShellMenuItem(ContextMenu contextMenu, object? tag)
async Task InvokeShellMenuItem(ContextMenu contextMenu, object? tag)
{
if (tag is not Win32ContextMenuItem menuItem)
return;
Expand Down
3 changes: 2 additions & 1 deletion src/Files.App/Helpers/StorageSenseHelper.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
using Files.App.Shell;
using System;
using System.Threading.Tasks;
using Windows.Foundation.Metadata;
using Windows.System;

namespace Files.App.Helpers
{
internal class StorageSenseHelper
{
public static async void OpenStorageSense(string path)
public static async Task OpenStorageSense(string path)
{
if (!path.StartsWith("C:", StringComparison.OrdinalIgnoreCase)
&& ApiInformation.IsApiContractPresent("Windows.Foundation.UniversalApiContract", 8))
Expand Down
4 changes: 2 additions & 2 deletions src/Files.App/Helpers/UIFilesystemHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public static class UIFilesystemHelpers
{
private static readonly OngoingTasksViewModel ongoingTasksViewModel = Ioc.Default.GetRequiredService<OngoingTasksViewModel>();

public static async void CutItem(IShellPage associatedInstance)
public static async Task CutItem(IShellPage associatedInstance)
{
DataPackage dataPackage = new DataPackage()
{
Expand Down Expand Up @@ -280,7 +280,7 @@ public static async Task<bool> RenameFileItemAsync(ListedItem item, string newNa
return false;
}

public static async void CreateFileFromDialogResultType(AddItemDialogItemType itemType, ShellNewEntry itemInfo, IShellPage associatedInstance)
public static async Task CreateFileFromDialogResultType(AddItemDialogItemType itemType, ShellNewEntry itemInfo, IShellPage associatedInstance)
{
await CreateFileFromDialogResultTypeForResult(itemType, itemInfo, associatedInstance);
}
Expand Down
3 changes: 2 additions & 1 deletion src/Files.App/Helpers/WallpaperHelpers.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using Files.Shared.Enums;
using System;
using System.Linq;
using System.Threading.Tasks;
using Vanara.PInvoke;
using Windows.Storage;
using Windows.System.UserProfile;
Expand All @@ -9,7 +10,7 @@ namespace Files.App.Helpers
{
public static class WallpaperHelpers
{
public static async void SetAsBackground(WallpaperType type, string filePath)
public static async Task SetAsBackground(WallpaperType type, string filePath)
{
if (type == WallpaperType.Desktop)
{
Expand Down
3 changes: 2 additions & 1 deletion src/Files.App/IShellPage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using Files.App.Views;
using System;
using System.ComponentModel;
using System.Threading.Tasks;

namespace Files.App
{
Expand All @@ -28,7 +29,7 @@ public interface IShellPage : ITabItemContent, IMultiPaneInfo, IDisposable, INot

bool CanNavigateForward { get; }

void Refresh_Click();
Task Refresh_Click();

void Back_Click();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ private void OpenPropertiesFromBaseContextMenuFlyout(object sender, object e)
FilePropertiesHelpers.ShowProperties(associatedInstance);
}

public virtual async void OpenDirectoryInNewTab(RoutedEventArgs e)
public virtual async Task OpenDirectoryInNewTab(RoutedEventArgs e)
{
foreach (ListedItem listedItem in SlimContentPage.SelectedItems)
{
Expand All @@ -113,7 +113,7 @@ public virtual void OpenDirectoryInNewPane(RoutedEventArgs e)
NavigationHelpers.OpenInSecondaryPane(associatedInstance, SlimContentPage.SelectedItems.FirstOrDefault());
}

public virtual async void OpenInNewWindowItem(RoutedEventArgs e)
public virtual async Task OpenInNewWindowItem(RoutedEventArgs e)
{
List<ListedItem> items = SlimContentPage.SelectedItems;

Expand All @@ -130,7 +130,7 @@ public virtual void CreateNewFile(ShellNewEntry f)
UIFilesystemHelpers.CreateFileFromDialogResultType(AddItemDialogItemType.File, f, associatedInstance);
}

public virtual async void ItemPointerPressed(PointerRoutedEventArgs e)
public virtual async Task ItemPointerPressed(PointerRoutedEventArgs e)
{
if (e.GetCurrentPoint(null).Properties.IsMiddleButtonPressed)
{
Expand Down
6 changes: 3 additions & 3 deletions src/Files.App/Interacts/BaseLayoutCommandsViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ public BaseLayoutCommandsViewModel(IBaseLayoutCommandImplementationModel command
private void InitializeCommands()
{
ShowPropertiesCommand = new RelayCommand<RoutedEventArgs>(CommandsModel.ShowProperties);
OpenDirectoryInNewTabCommand = new RelayCommand<RoutedEventArgs>(CommandsModel.OpenDirectoryInNewTab);
OpenDirectoryInNewTabCommand = new AsyncRelayCommand<RoutedEventArgs>(CommandsModel.OpenDirectoryInNewTab);
OpenDirectoryInNewPaneCommand = new RelayCommand<RoutedEventArgs>(CommandsModel.OpenDirectoryInNewPane);
OpenInNewWindowItemCommand = new RelayCommand<RoutedEventArgs>(CommandsModel.OpenInNewWindowItem);
OpenInNewWindowItemCommand = new AsyncRelayCommand<RoutedEventArgs>(CommandsModel.OpenInNewWindowItem);
CreateNewFileCommand = new RelayCommand<ShellNewEntry>(CommandsModel.CreateNewFile);
ItemPointerPressedCommand = new RelayCommand<PointerRoutedEventArgs>(CommandsModel.ItemPointerPressed);
ItemPointerPressedCommand = new AsyncRelayCommand<PointerRoutedEventArgs>(CommandsModel.ItemPointerPressed);
PointerWheelChangedCommand = new RelayCommand<PointerRoutedEventArgs>(CommandsModel.PointerWheelChanged);
DragOverCommand = new AsyncRelayCommand<DragEventArgs>(CommandsModel.DragOver);
DropCommand = new AsyncRelayCommand<DragEventArgs>(CommandsModel.Drop);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ public interface IBaseLayoutCommandImplementationModel : IDisposable
{
void ShowProperties(RoutedEventArgs e);

void OpenDirectoryInNewTab(RoutedEventArgs e);
Task OpenDirectoryInNewTab(RoutedEventArgs e);

void OpenDirectoryInNewPane(RoutedEventArgs e);

void OpenInNewWindowItem(RoutedEventArgs e);
Task OpenInNewWindowItem(RoutedEventArgs e);

void CreateNewFile(ShellNewEntry e);

void ItemPointerPressed(PointerRoutedEventArgs e);
Task ItemPointerPressed(PointerRoutedEventArgs e);

void PointerWheelChanged(PointerRoutedEventArgs e);

Expand Down
3 changes: 2 additions & 1 deletion src/Files.App/UserControls/FileIcon.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using Microsoft.UI.Xaml.Media.Imaging;
using System;
using System.Runtime.InteropServices.WindowsRuntime;
using System.Threading.Tasks;
using Windows.Storage.Streams;

namespace Files.App.UserControls
Expand Down Expand Up @@ -75,7 +76,7 @@ public FileIcon()
InitializeComponent();
}

public async void UpdateImageSourceAsync()
public async Task UpdateImageSourceAsync()
{
if (FileIconImageData is not null)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Linq;
using System.Threading.Tasks;

namespace Files.App.UserControls.MultitaskingControl
{
Expand Down Expand Up @@ -121,7 +122,7 @@ public List<ITabItemContent> GetAllTabInstances()
return MainPageViewModel.AppInstances.Select(x => x.Control?.TabItemContent).ToList();
}

public async void ReopenClosedTab()
public async Task ReopenClosedTab()
{
if (!IsRestoringClosedTab && RecentlyClosedTabs.Count > 0)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Threading.Tasks;

namespace Files.App.UserControls.MultitaskingControl
{
Expand All @@ -14,7 +15,7 @@ public interface IMultitaskingControl

public List<ITabItemContent> GetAllTabInstances();

public void ReopenClosedTab();
public Task ReopenClosedTab();

public void CloseTab(TabItem tabItem);

Expand Down
24 changes: 12 additions & 12 deletions src/Files.App/UserControls/SidebarControl.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,9 @@ public UIElement TabContent
set => SetValue(TabContentProperty, value);
}

public readonly ICommand CreateLibraryCommand = new RelayCommand(LibraryManager.ShowCreateNewLibraryDialog);
public readonly ICommand CreateLibraryCommand = new AsyncRelayCommand(LibraryManager.ShowCreateNewLibraryDialog);

public readonly ICommand RestoreLibrariesCommand = new RelayCommand(LibraryManager.ShowRestoreDefaultLibrariesDialog);
public readonly ICommand RestoreLibrariesCommand = new AsyncRelayCommand(LibraryManager.ShowRestoreDefaultLibrariesDialog);

private ICommand HideSectionCommand { get; }

Expand Down Expand Up @@ -139,13 +139,13 @@ public SidebarControl()
HideSectionCommand = new RelayCommand(HideSection);
UnpinItemCommand = new RelayCommand(UnpinItem);
PinItemCommand = new RelayCommand(PinItem);
OpenInNewTabCommand = new RelayCommand(OpenInNewTab);
OpenInNewWindowCommand = new RelayCommand(OpenInNewWindow);
OpenInNewPaneCommand = new RelayCommand(OpenInNewPane);
EjectDeviceCommand = new RelayCommand(EjectDevice);
OpenInNewTabCommand = new AsyncRelayCommand(OpenInNewTab);
OpenInNewWindowCommand = new AsyncRelayCommand(OpenInNewWindow);
OpenInNewPaneCommand = new AsyncRelayCommand(OpenInNewPane);
EjectDeviceCommand = new AsyncRelayCommand(EjectDevice);
FormatDriveCommand = new RelayCommand(FormatDrive);
OpenPropertiesCommand = new RelayCommand<CommandBarFlyout>(OpenProperties);
ReorderItemsCommand = new RelayCommand(ReorderItems);
ReorderItemsCommand = new AsyncRelayCommand(ReorderItems);
}

public SidebarViewModel ViewModel
Expand Down Expand Up @@ -342,30 +342,30 @@ private void HideSection()
}
}

private async void ReorderItems()
private async Task ReorderItems()
{
var dialog = new ReorderSidebarItemsDialogViewModel();
var dialogService = Ioc.Default.GetRequiredService<IDialogService>();
var result = await dialogService.ShowDialogAsync(dialog);
}

private async void OpenInNewPane()
private async Task OpenInNewPane()
{
if (await DriveHelpers.CheckEmptyDrive(rightClickedItem.Path))
return;

SidebarItemNewPaneInvoked?.Invoke(this, new SidebarItemNewPaneInvokedEventArgs(rightClickedItem));
}

private async void OpenInNewTab()
private async Task OpenInNewTab()
{
if (await DriveHelpers.CheckEmptyDrive(rightClickedItem.Path))
return;

await NavigationHelpers.OpenPathInNewTab(rightClickedItem.Path);
}

private async void OpenInNewWindow()
private async Task OpenInNewWindow()
{
if (await DriveHelpers.CheckEmptyDrive(rightClickedItem.Path))
return;
Expand Down Expand Up @@ -395,7 +395,7 @@ private void OpenProperties(CommandBarFlyout menu)
menu.Closed += flyoutClosed;
}

private async void EjectDevice()
private async Task EjectDevice()
{
var result = await DriveHelpers.EjectDeviceAsync(rightClickedItem.Path);
await UIHelpers.ShowDeviceEjectResultAsync(result);
Expand Down
8 changes: 4 additions & 4 deletions src/Files.App/UserControls/Widgets/DrivesWidget.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -134,12 +134,12 @@ public DrivesWidget()

FormatDriveCommand = new RelayCommand<DriveCardItem>(FormatDrive);
EjectDeviceCommand = new AsyncRelayCommand<DriveCardItem>(EjectDevice);
OpenInNewTabCommand = new RelayCommand<WidgetCardItem>(OpenInNewTab);
OpenInNewWindowCommand = new RelayCommand<WidgetCardItem>(OpenInNewWindow);
OpenInNewTabCommand = new AsyncRelayCommand<WidgetCardItem>(OpenInNewTab);
OpenInNewWindowCommand = new AsyncRelayCommand<WidgetCardItem>(OpenInNewWindow);
OpenInNewPaneCommand = new AsyncRelayCommand<DriveCardItem>(OpenInNewPane);
OpenPropertiesCommand = new RelayCommand<DriveCardItem>(OpenProperties);
PinToFavoritesCommand = new RelayCommand<WidgetCardItem>(PinToFavorites);
UnpinFromFavoritesCommand = new RelayCommand<WidgetCardItem>(UnpinFromFavorites);
PinToFavoritesCommand = new AsyncRelayCommand<WidgetCardItem>(PinToFavorites);
UnpinFromFavoritesCommand = new AsyncRelayCommand<WidgetCardItem>(UnpinFromFavorites);
MapNetworkDriveCommand = new AsyncRelayCommand(DoNetworkMapDrive);
DisconnectNetworkDriveCommand = new RelayCommand<DriveCardItem>(DisconnectNetworkDrive);
}
Expand Down
8 changes: 4 additions & 4 deletions src/Files.App/UserControls/Widgets/FileTagsWidget.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,12 @@ public FileTagsWidget()
// Second function is layered on top to ensure that OpenPath function is late initialized and a null reference is not passed-in
// See FileTagItemViewModel._openAction for more information
ViewModel = new(x => OpenAction!(x));
OpenInNewTabCommand = new RelayCommand<WidgetCardItem>(OpenInNewTab);
OpenInNewWindowCommand = new RelayCommand<WidgetCardItem>(OpenInNewWindow);
OpenInNewTabCommand = new AsyncRelayCommand<WidgetCardItem>(OpenInNewTab);
OpenInNewWindowCommand = new AsyncRelayCommand<WidgetCardItem>(OpenInNewWindow);
OpenFileLocationCommand = new RelayCommand<WidgetCardItem>(OpenFileLocation);
OpenInNewPaneCommand = new RelayCommand<WidgetCardItem>(OpenInNewPane);
PinToFavoritesCommand = new RelayCommand<WidgetCardItem>(PinToFavorites);
UnpinFromFavoritesCommand = new RelayCommand<WidgetCardItem>(UnpinFromFavorites);
PinToFavoritesCommand = new AsyncRelayCommand<WidgetCardItem>(PinToFavorites);
UnpinFromFavoritesCommand = new AsyncRelayCommand<WidgetCardItem>(UnpinFromFavorites);
OpenPropertiesCommand = new RelayCommand<WidgetCardItem>(OpenProperties);
}

Expand Down
Loading