visioforge / .Net-SDK-s-samples

VisioForge .Net SDKs samples - Video Capture SDK, Video Edit SDK, Media Player SDK, Media Blocks SDK, Video Fingerprinting SDK
https://www.visioforge.com
MIT License
51 stars 26 forks source link

VideoCaptureCore StopAsync Winforms FormClosing Problem #9

Closed idgregory closed 2 years ago

idgregory commented 2 years ago

Hello,

When I try to stop video capture on the FormClosing Event in a WinForms application. I always get this exception: "Invoke or BeginInvoke cannot be called on a control until the window handle has been created"

Here's the code:

private async void PictureDialog_FormClosing(object sender, FormClosingEventArgs e) { if (_captureCore.State() != PlaybackState.Free) await _captureCore.StopAsync(); if (File.Exists("output.mp4")) File.Delete("output.mp4"); }

Is there a better way of handling the window closing and stopping the video? I noticed that the camera and file are still "in use" even after the form is destroyed.

Thanks

visioforge commented 2 years ago

I suggest overriding form Dispose method call like shown in our demo app - https://github.com/visioforge/.Net-SDK-s-samples/blob/master/Video%20Capture%20SDK/WinForms/CSharp/Main%20Demo/Form1.Designer.cs