-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Code Quality: Replaced DllImport calls with CsWin32 generations for event object operations #17086
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 | ||||
---|---|---|---|---|---|---|
|
@@ -5,6 +5,8 @@ | |||||
using Microsoft.Extensions.Logging; | ||||||
using Microsoft.UI.Xaml; | ||||||
using Microsoft.UI.Xaml.Controls; | ||||||
using Windows.Win32.Foundation; | ||||||
using Windows.Win32; | ||||||
using Microsoft.Windows.AppLifecycle; | ||||||
using Windows.ApplicationModel; | ||||||
using Windows.ApplicationModel.DataTransfer; | ||||||
|
@@ -223,9 +225,15 @@ private async void Window_Closed(object sender, WindowEventArgs args) | |||||
var results = items.Select(x => x.ItemPath).ToList(); | ||||||
System.IO.File.WriteAllLines(OutputPath, results); | ||||||
|
||||||
IntPtr eventHandle = Win32PInvoke.CreateEvent(IntPtr.Zero, false, false, "FILEDIALOG"); | ||||||
Win32PInvoke.SetEvent(eventHandle); | ||||||
Win32PInvoke.CloseHandle(eventHandle); | ||||||
unsafe | ||||||
{ | ||||||
fixed (char* fileDialog = "FILEDIALOG") | ||||||
{ | ||||||
HANDLE eventHandle = PInvoke.CreateEvent(bManualReset: false, bInitialState: false, lpName: fileDialog); | ||||||
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. Can't you just:
Suggested change
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. Also hEventHandle please. |
||||||
PInvoke.SetEvent(eventHandle); | ||||||
PInvoke.CloseHandle(eventHandle); | ||||||
} | ||||||
} | ||||||
} | ||||||
|
||||||
// Continue running the app on the background | ||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,8 @@ | |
using Microsoft.UI.Dispatching; | ||
using Microsoft.UI.Xaml; | ||
using Microsoft.Windows.AppLifecycle; | ||
using Windows.Win32; | ||
using Windows.Win32.Foundation; | ||
using System.IO; | ||
using System.Text; | ||
using Windows.ApplicationModel.Activation; | ||
|
@@ -248,17 +250,17 @@ private static async void OnActivated(object? sender, AppActivationArguments arg | |
/// <remarks> | ||
/// Redirects on another thread and uses a non-blocking wait method to wait for the redirection to complete. | ||
/// </remarks> | ||
public static void RedirectActivationTo(AppInstance keyInstance, AppActivationArguments args) | ||
public static unsafe void RedirectActivationTo(AppInstance keyInstance, AppActivationArguments args) | ||
{ | ||
IntPtr eventHandle = CreateEvent(IntPtr.Zero, true, false, null); | ||
HANDLE eventHandle = PInvoke.CreateEvent(bManualReset: true, bInitialState: false, lpName: null); | ||
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. As above. |
||
|
||
Task.Run(() => | ||
{ | ||
keyInstance.RedirectActivationToAsync(args).AsTask().Wait(); | ||
SetEvent(eventHandle); | ||
PInvoke.SetEvent(eventHandle); | ||
}); | ||
|
||
_ = CoWaitForMultipleObjects( | ||
_ = Win32PInvoke.CoWaitForMultipleObjects( | ||
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. Pretty sure you should pin the array. |
||
CWMO_DEFAULT, | ||
INFINITE, | ||
1, | ||
|
@@ -271,14 +273,14 @@ public static void OpenShellCommandInExplorer(string shellCommand, int pid) | |
Win32Helper.OpenFolderInExistingShellWindow(shellCommand); | ||
} | ||
|
||
public static void OpenFileFromTile(string filePath) | ||
public static unsafe void OpenFileFromTile(string filePath) | ||
{ | ||
IntPtr eventHandle = CreateEvent(IntPtr.Zero, true, false, null); | ||
HANDLE eventHandle = PInvoke.CreateEvent(bManualReset: true, bInitialState: false, lpName: null); | ||
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. As above. |
||
|
||
Task.Run(() => | ||
{ | ||
LaunchHelper.LaunchAppAsync(filePath, null, null).Wait(); | ||
SetEvent(eventHandle); | ||
PInvoke.SetEvent(eventHandle); | ||
}); | ||
|
||
_ = CoWaitForMultipleObjects( | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,6 +14,7 @@ | |
using System.Runtime.CompilerServices; | ||
using System.Runtime.InteropServices; | ||
using Vanara.Windows.Shell; | ||
using Windows.Win32; | ||
using Windows.Foundation; | ||
using Windows.Storage; | ||
using Windows.Storage.FileProperties; | ||
|
@@ -2124,7 +2125,7 @@ private void WatchForDirectoryChanges(string path, CloudDriveSyncStatus syncStat | |
notifyFilters |= FILE_NOTIFY_CHANGE_ATTRIBUTES; | ||
|
||
var overlapped = new OVERLAPPED(); | ||
overlapped.hEvent = CreateEvent(IntPtr.Zero, false, false, null); | ||
overlapped.hEvent = PInvoke.CreateEvent(null, false, false, null).DangerousGetHandle(); | ||
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. As above. |
||
const uint INFINITE = 0xFFFFFFFF; | ||
|
||
while (x.Status != AsyncStatus.Canceled) | ||
|
@@ -2235,7 +2236,7 @@ private void WatchForGitChanges() | |
var notifyFilters = FILE_NOTIFY_CHANGE_DIR_NAME | FILE_NOTIFY_CHANGE_FILE_NAME | FILE_NOTIFY_CHANGE_LAST_WRITE | FILE_NOTIFY_CHANGE_SIZE | FILE_NOTIFY_CHANGE_CREATION; | ||
|
||
var overlapped = new OVERLAPPED(); | ||
overlapped.hEvent = CreateEvent(IntPtr.Zero, false, false, null); | ||
overlapped.hEvent = PInvoke.CreateEvent(null, false, false, null).DangerousGetHandle(); | ||
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. Asa above. |
||
const uint INFINITE = 0xFFFFFFFF; | ||
|
||
while (x.Status != AsyncStatus.Canceled) | ||
|
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.
pszEventObjectName please.