-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Code Quality: Introduced a wrapper for non-blocking await on a sync method #17100
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,7 +9,6 @@ | |
using System.Text; | ||
using Windows.ApplicationModel.Activation; | ||
using Windows.Storage; | ||
using static Files.App.Helpers.Win32PInvoke; | ||
|
||
namespace Files.App | ||
{ | ||
|
@@ -21,9 +20,6 @@ namespace Files.App | |
/// </remarks> | ||
internal sealed class Program | ||
{ | ||
private const uint CWMO_DEFAULT = 0; | ||
private const uint INFINITE = 0xFFFFFFFF; | ||
|
||
public static Semaphore? Pool { get; set; } | ||
|
||
static Program() | ||
|
@@ -250,20 +246,10 @@ private static async void OnActivated(object? sender, AppActivationArguments arg | |
/// </remarks> | ||
public static void RedirectActivationTo(AppInstance keyInstance, AppActivationArguments args) | ||
{ | ||
IntPtr eventHandle = CreateEvent(IntPtr.Zero, true, false, null); | ||
|
||
Task.Run(() => | ||
STATask.RunAsSync(() => | ||
{ | ||
keyInstance.RedirectActivationToAsync(args).AsTask().Wait(); | ||
SetEvent(eventHandle); | ||
}); | ||
|
||
_ = CoWaitForMultipleObjects( | ||
CWMO_DEFAULT, | ||
INFINITE, | ||
1, | ||
[eventHandle], | ||
out uint handleIndex); | ||
} | ||
|
||
public static void OpenShellCommandInExplorer(string shellCommand, int pid) | ||
|
@@ -273,20 +259,10 @@ public static void OpenShellCommandInExplorer(string shellCommand, int pid) | |
|
||
public static void OpenFileFromTile(string filePath) | ||
{ | ||
IntPtr eventHandle = CreateEvent(IntPtr.Zero, true, false, null); | ||
|
||
Task.Run(() => | ||
STATask.RunAsSync(() => | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there a reason why async void isn't desirable here? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So you mean adding Wait() in that helper method instead? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I mean making it an async lambda and then |
||
{ | ||
LaunchHelper.LaunchAppAsync(filePath, null, null).Wait(); | ||
SetEvent(eventHandle); | ||
}); | ||
|
||
_ = CoWaitForMultipleObjects( | ||
CWMO_DEFAULT, | ||
INFINITE, | ||
1, | ||
[eventHandle], | ||
out uint handleIndex); | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you even need to allocate a stack here? I thought your HANDLE variable is in stack already.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Related to your 2nd comment, it looks like you can't take address of a local variable that goes thru an async lambda/function. The current code doesn't have async and initially did so this can be refactored but IIUC if we wanna use async void we may have to do this.