diff --git a/src/ComputeSharp/Graphics/GraphicsDevice.DeviceLost.cs b/src/ComputeSharp/Graphics/GraphicsDevice.DeviceLost.cs
index 2e67481e..f0c5149f 100644
--- a/src/ComputeSharp/Graphics/GraphicsDevice.DeviceLost.cs
+++ b/src/ComputeSharp/Graphics/GraphicsDevice.DeviceLost.cs
@@ -105,7 +105,12 @@ unsafe partial class GraphicsDevice
/// The current instance.
/// The resulting used as callback state.
/// The resulting device lost event for the callback.
- private static void RegisterDeviceLostCallback(GraphicsDevice device, out GCHandle deviceHandle, out HANDLE deviceRemovedEvent)
+ /// The resulting device lost wait handle for the callback.
+ private static void RegisterDeviceLostCallback(
+ GraphicsDevice device,
+ out GCHandle deviceHandle,
+ out HANDLE deviceRemovedEvent,
+ out HANDLE deviceRemovedWaitHandle)
{
HANDLE eventHandle = Windows.CreateEventW(null, Windows.FALSE, Windows.FALSE, null);
@@ -128,7 +133,8 @@ unsafe partial class GraphicsDevice
dwMilliseconds: Windows.INFINITE,
dwFlags: 0);
- deviceRemovedEvent = waitHandle;
+ deviceRemovedEvent = eventHandle;
+ deviceRemovedWaitHandle = waitHandle;
}
///
@@ -137,7 +143,7 @@ unsafe partial class GraphicsDevice
/// The current instance.
private static void UnregisterDeviceLostCallback(GraphicsDevice device)
{
- _ = Windows.UnregisterWait(device.deviceRemovedEvent);
+ _ = Windows.UnregisterWait(device.deviceRemovedWaitHandle);
_ = Windows.CloseHandle(device.deviceRemovedEvent);
device.deviceHandle.Free();
diff --git a/src/ComputeSharp/Graphics/GraphicsDevice.cs b/src/ComputeSharp/Graphics/GraphicsDevice.cs
index 6e7ad77e..66602ebd 100644
--- a/src/ComputeSharp/Graphics/GraphicsDevice.cs
+++ b/src/ComputeSharp/Graphics/GraphicsDevice.cs
@@ -93,10 +93,15 @@ public sealed unsafe partial class GraphicsDevice : NativeObject
private GCHandle deviceHandle;
///
- /// The wait event for the device removed.
+ /// The event for the device removed callback.
///
private HANDLE deviceRemovedEvent;
+ ///
+ /// The wait handle for the device removed callback.
+ ///
+ private HANDLE deviceRemovedWaitHandle;
+
///
/// The reason the device was removed, if any.
///
@@ -166,7 +171,7 @@ public sealed unsafe partial class GraphicsDevice : NativeObject
this.deviceRemovedReason = S.S_OK;
- RegisterDeviceLostCallback(this, out this.deviceHandle, out this.deviceRemovedEvent);
+ RegisterDeviceLostCallback(this, out this.deviceHandle, out this.deviceRemovedEvent, out this.deviceRemovedWaitHandle);
}
///