Browse Source

Fix interrupt handler disposed too early

pull/165/head
Ionite 1 year ago
parent
commit
48b81afc68
No known key found for this signature in database
  1. 16
      StabilityMatrix.Avalonia/ViewModels/Base/InferenceGenerationViewModelBase.cs
  2. 7
      StabilityMatrix.Avalonia/ViewModels/Base/ProgressViewModel.cs

16
StabilityMatrix.Avalonia/ViewModels/Base/InferenceGenerationViewModelBase.cs

@ -132,7 +132,19 @@ public abstract partial class InferenceGenerationViewModelBase
// Register progress handler
promptTask.ProgressUpdate += OnProgressUpdateReceived;
// Delay attaching running node change handler to not show indeterminate progress
// if progress updates are received before the prompt starts
Task.Run(
async () =>
{
await Task.Delay(200, cancellationToken);
// ReSharper disable once AccessToDisposedClosure
promptTask.RunningNodeChanged += OnRunningNodeChanged;
},
cancellationToken
)
.SafeFireAndForget();
// Wait for prompt to finish
await promptTask.Task.WaitAsync(cancellationToken);
@ -166,15 +178,13 @@ public abstract partial class InferenceGenerationViewModelBase
client.PreviewImageReceived -= OnPreviewImageReceived;
// Clear progress
OutputProgress.Value = 0;
OutputProgress.Text = "";
OutputProgress.ClearProgress();
ImageGalleryCardViewModel.PreviewImage?.Dispose();
ImageGalleryCardViewModel.PreviewImage = null;
ImageGalleryCardViewModel.IsPreviewOverlayEnabled = false;
// Cleanup tasks
promptTask?.Dispose();
await promptInterrupt.DisposeAsync();
}
}

7
StabilityMatrix.Avalonia/ViewModels/Base/ProgressViewModel.cs

@ -24,4 +24,11 @@ public partial class ProgressViewModel : ViewModelBase
public virtual bool IsProgressVisible => Value > 0 || IsIndeterminate;
public virtual bool IsTextVisible => !string.IsNullOrWhiteSpace(Text);
public void ClearProgress()
{
Value = 0;
Text = null;
IsIndeterminate = false;
}
}

Loading…
Cancel
Save