File tree Expand file tree Collapse file tree 1 file changed +9
-1
lines changed Expand file tree Collapse file tree 1 file changed +9
-1
lines changed Original file line number Diff line number Diff line change @@ -33,7 +33,11 @@ public static class OverlappedAsync
3333 if ( ! handle . SafeWaitHandle . IsClosed )
3434 try
3535 {
36- handle . WaitOne ( millisecondsTimeout , exitContext ) ;
36+ if ( ! handle . WaitOne ( millisecondsTimeout , exitContext ) )
37+ {
38+ unsafe { CancelIoEx ( result . Handle , result . Overlapped ) ; }
39+ throw new TimeoutException ( "The operation has timed out." , new Win32Exception ( Marshal . GetLastWin32Error ( ) ) ) ;
40+ }
3741 }
3842 finally
3943 {
@@ -114,6 +118,10 @@ private static void BindHandle(HFILE hDevice)
114118 ThreadPool . BindHandle ( new Microsoft . Win32 . SafeHandles . SafeFileHandle ( ( IntPtr ) hDevice , false ) ) ;
115119 }
116120
121+ [ DllImport ( Lib . Kernel32 , SetLastError = true , ExactSpelling = true ) ]
122+ [ return : MarshalAs ( UnmanagedType . Bool ) ]
123+ private static unsafe extern bool CancelIoEx ( [ In ] HFILE hFile , [ In , Optional ] NativeOverlapped * lpOverlapped ) ;
124+
117125 /// <summary>Holds all pertinent information for handling results and errors in an overlapped set of method calls.</summary>
118126 /// <seealso cref="IAsyncResult"/>
119127 public sealed class OverlappedAsyncResult : IAsyncResult
You can’t perform that action at this time.
0 commit comments