55using Microsoft . UI . Dispatching ;
66using Microsoft . UI . Xaml ;
77using Microsoft . Windows . AppLifecycle ;
8+ using Windows . Win32 ;
9+ using Windows . Win32 . Foundation ;
810using System . IO ;
911using System . Text ;
1012using Windows . ApplicationModel . Activation ;
1113using Windows . Storage ;
1214using static Files . App . Helpers . Win32PInvoke ;
15+ using Microsoft . Win32 . SafeHandles ;
1316
1417namespace Files . App
1518{
@@ -250,19 +253,19 @@ private static async void OnActivated(object? sender, AppActivationArguments arg
250253 /// </remarks>
251254 public static void RedirectActivationTo ( AppInstance keyInstance , AppActivationArguments args )
252255 {
253- IntPtr eventHandle = CreateEvent ( IntPtr . Zero , true , false , null ) ;
256+ SafeFileHandle eventHandle = PInvoke . CreateEvent ( null , true , false , null ) ;
254257
255258 Task . Run ( ( ) =>
256259 {
257260 keyInstance . RedirectActivationToAsync ( args ) . AsTask ( ) . Wait ( ) ;
258- SetEvent ( eventHandle ) ;
261+ PInvoke . SetEvent ( eventHandle ) ;
259262 } ) ;
260263
261- _ = CoWaitForMultipleObjects (
264+ _ = Win32PInvoke . CoWaitForMultipleObjects (
262265 CWMO_DEFAULT ,
263266 INFINITE ,
264267 1 ,
265- [ eventHandle ] ,
268+ [ eventHandle . DangerousGetHandle ( ) ] ,
266269 out uint handleIndex ) ;
267270 }
268271
@@ -273,19 +276,19 @@ public static void OpenShellCommandInExplorer(string shellCommand, int pid)
273276
274277 public static void OpenFileFromTile ( string filePath )
275278 {
276- IntPtr eventHandle = CreateEvent ( IntPtr . Zero , true , false , null ) ;
279+ SafeFileHandle eventHandle = PInvoke . CreateEvent ( null , true , false , null ) ;
277280
278281 Task . Run ( ( ) =>
279282 {
280283 LaunchHelper . LaunchAppAsync ( filePath , null , null ) . Wait ( ) ;
281- SetEvent ( eventHandle ) ;
284+ PInvoke . SetEvent ( eventHandle ) ;
282285 } ) ;
283286
284287 _ = CoWaitForMultipleObjects (
285288 CWMO_DEFAULT ,
286289 INFINITE ,
287290 1 ,
288- [ eventHandle ] ,
291+ [ eventHandle . DangerousGetHandle ( ) ] ,
289292 out uint handleIndex ) ;
290293 }
291294 }
0 commit comments