Skip to content

Commit 2f17c10

Browse files
author
Gerardo Lijs
committed
bugfix: close app and task cancelled exception
1 parent 799d6ca commit 2f17c10

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

src/MachineLearning.ObjectDetect.WPF/Views/WebcamView.xaml.cs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,18 @@ public WebcamView()
5555
ViewModel.CameraOpenCv.ImageGrabbed.Subscribe(async imageGrabbedData =>
5656
{
5757
// Update frame in UI thread
58-
await System.Windows.Application.Current.Dispatcher.InvokeAsync(() =>
58+
try
5959
{
60-
CurrentFPSTextBlock.Text = imageGrabbedData.CurrentFPS.ToString("N1");
61-
WebcamImage.Source = imageGrabbedData.image.ToBitmapSource();
62-
});
60+
await System.Windows.Application.Current.Dispatcher.InvokeAsync(() =>
61+
{
62+
CurrentFPSTextBlock.Text = imageGrabbedData.CurrentFPS.ToString("N1");
63+
WebcamImage.Source = imageGrabbedData.image.ToBitmapSource();
64+
});
65+
}
66+
catch (TaskCanceledException)
67+
{
68+
// App shutting down
69+
}
6370
}).DisposeWith(disposableRegistration);
6471

6572
// Interactions

0 commit comments

Comments
 (0)