stop inference on stop pressed

small fixes
This commit is contained in:
Alex Bezdieniezhnykh
2025-03-24 10:52:32 +02:00
parent 6429ad62c2
commit 73c2ab5374
11 changed files with 40 additions and 29 deletions
+7 -6
View File
@@ -393,6 +393,7 @@ public partial class Annotator
private void OnFormClosed(object? sender, EventArgs e)
{
MainCancellationSource.Cancel();
_inferenceService.StopInference();
DetectionCancellationSource.Cancel();
_mediaPlayer.Stop();
_mediaPlayer.Dispose();
@@ -500,30 +501,30 @@ public partial class Annotator
IsInferenceNow = true;
FollowAI = true;
DetectionCancellationSource = new CancellationTokenSource();
var ct = DetectionCancellationSource.Token;
var detectToken = DetectionCancellationSource.Token;
_ = Task.Run(async () =>
{
while (!ct.IsCancellationRequested)
while (!detectToken.IsCancellationRequested)
{
var files = new List<string>();
await Dispatcher.Invoke(async () =>
{
//Take not annotataed medias
//Take all medias
files = (LvFiles.ItemsSource as IEnumerable<MediaFileInfo>)?.Skip(LvFiles.SelectedIndex)
.Where(x => !x.HasAnnotations)
//.Where(x => !x.HasAnnotations)
.Take(Constants.DETECTION_BATCH_SIZE)
.Select(x => x.Path)
.ToList() ?? [];
if (files.Count != 0)
{
await _mediator.Publish(new AnnotatorControlEvent(PlaybackControlEnum.Play), ct);
await _mediator.Publish(new AnnotatorControlEvent(PlaybackControlEnum.Play), detectToken);
await ReloadAnnotations();
}
});
if (files.Count == 0)
break;
await _inferenceService.RunInference(files, async annotationImage => await ProcessDetection(annotationImage, ct), ct);
await _inferenceService.RunInference(files, async annotationImage => await ProcessDetection(annotationImage, detectToken), detectToken);
Dispatcher.Invoke(() =>
{