Skip to content

[BUG] [Windows] CameraView.CaptureImage hangs forever if the preview is stopped while a capture is in flight, and every later capture on that CameraView then hangs #3360

Closed

Description

@alex-tay-nec

Is there an existing issue for this?

  • I have searched the existing issues

Did you read the "Reporting a bug" section on Contributing file?

Current Behavior

On Windows, if StopCameraPreview runs (or the CameraView is unloaded) while CaptureImage is awaiting MediaCapture.CapturePhotoToStreamAsync, the capture never completes. Neither MediaCaptured nor MediaCaptureFailed is raised, and cancelling the CancellationToken does not unblock the underlying call.

captureImageSemaphoreSlim is released only in the finally of CaptureImage. That finally never runs, so the semaphore stays at 0. Every later CaptureImage call on the same CameraView waits on the semaphore until it times out or is cancelled. I confirmed this by reflection. Before any new capture on the next session, the semaphore count was 0 and the MediaCapture stream state was NotStreaming.

Is there an existing issue? Searched. Related but different: #3322 (iOS CaptureImage hang), #2208 (rapid capture on Windows and iOS).

Expected Behavior

When the preview is stopped, a pending CaptureImage should fail promptly, for example with MediaCaptureFailed or an exception. Alternatively, the stop should wait for the capture to finish. The semaphore should always be released. CaptureImage should not hang, and the CameraView should stay usable.

Steps To Reproduce

  1. Create a page with a CameraView. Call StartCameraPreview and wait for Loaded.
  2. Call await cameraView.CaptureImage(token) in a loop.
  3. A few milliseconds after a capture starts (about 5–8 ms in my case), call StopCameraPreview or navigate away so the view unloads.
  4. Repeat the start, capture, stop cycle on the same CameraView instance.
  5. Sooner or later one CaptureImage never returns. Later calls on that instance also hang.

The race is random. In my app it showed up in a minority of cycles, with captures running back to back at about 65 ms each.

Link to public reproduction project repository

https://github.com/alex-tay-nec/CameraCaptureHangRepro.git

Environment

- `CommunityToolkit.Maui.Camera` 6.1.0
- `Microsoft.Maui.Controls` 10.0.120
- .NET 10, `net10.0-windows10.0.26100.0`
- Windows 11

Anything else?

Workaround

Create a new CameraView (a new page) for each session, and treat a capture timeout as a fault that requires discarding the view.

Suggested fix directions

  • Track the in-flight capture task in the Windows camera manager. Have the stop wait for it, or fail it, before disposing MediaCapture.
  • Race the platform capture against the token, so cancellation actually frees the semaphore.

Activity

  1. locked and limited conversation to collaborators on Nov 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions