Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 14 additions & 7 deletions src/ui/Features/Video/OpenFromUrl/DownloadVideoFromUrlViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,15 @@ private static void TryDeleteDirectory(string path)
private readonly Lock _lockObj = new();

private void OnTimerElapsed(object? sender, ElapsedEventArgs e)
{
// System.Timers.Timer raises Elapsed on a thread-pool thread, but this handler
// writes observable properties bound to the UI (StatusText/Error) and closes the
// window. Touching those off the UI thread can throw "call from invalid thread" or
// leave the UI in an inconsistent state, so marshal the whole tick to the UI thread.
Dispatcher.UIThread.Post(HandleTimerTick);
}

private void HandleTimerTick()
{
lock (_lockObj)
{
Expand Down Expand Up @@ -305,15 +314,13 @@ private void CommandCancel()

private void Close()
{
Dispatcher.UIThread.Post(() =>
// Always invoked on the UI thread (HandleTimerTick / CommandCancel).
if (!string.IsNullOrEmpty(Error))
{
if (!string.IsNullOrEmpty(Error))
{
return; // keep window open so the user can read the error
}
return; // keep window open so the user can read the error
}

Window?.Close();
});
Window?.Close();
}

internal void OnKeyDown(KeyEventArgs e)
Expand Down