Exemple #1
0
        private async Task StopOperationAsync()
        {
            Stopwatch.Stop();
            await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
            {
                CaptureElement.Source = null;
            });

            FrameReader.FrameArrived -= FrameReader_FrameArrived;

            try
            {
                await MediaCapture.StopPreviewAsync();
            }
            catch (Exception e) when(e.HResult == unchecked ((int)0xc00dabe4) &&
                                     MediaCapture.PreviewMediaCapture.CameraStreamState != CameraStreamState.Streaming)
            {
                // StopPreview is not idempotent, silence exception when camera is not streaming
            }

            await FrameReader.StopAsync();

            FrameCollection.Dispose();
            CollectedColorFrames.AsParallel().ForAll(frame => frame.Dispose());
            CollectedNonIlluminatedInfraredFrames.AsParallel().ForAll(frame => frame.Dispose());
            CollectedIlluminatedInfraredFrames.AsParallel().ForAll(frame => frame.Dispose());
            CollectedColorFrames.Clear();
            CollectedNonIlluminatedInfraredFrames.Clear();
            CollectedIlluminatedInfraredFrames.Clear();

            await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, DispatcherTimer.Stop);
        }
Exemple #2
0
        private async Task StopOperationAsync()
        {
            MediaCapture.FaceDetected -= MediaCapture_FaceDetected;
            FrameReader.FrameArrived  -= FrameReader_FrameArrived;

            await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
            {
                CaptureElement.Source = null;
            });

            await MediaCapture.StopPreviewAsync();

            await FrameReader.StopAsync();

            FrameCollection.Dispose();
            ColorFrameEpochs.Clear();
            IlluminatedInfraredFrameEpochs.Clear();
            NonIlluminatedInfraredFrameEpochs.Clear();

            await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, DispatcherTimer.Stop);

            FrameReaderStopTrigger.Stop();
        }