Skip to content

Commit 70e4208

Browse files
claudebertyhell
authored andcommitted
enhance: use Dispatcher.UIThread.Post to hand refresh results to the UI thread
The background refresh tasks (branches, worktrees, tags, commits, submodules, local changes, stashes) and notification dispatching used the synchronous `Dispatcher.UIThread.Invoke`, which blocks a thread-pool thread until the UI thread has processed the update. Nothing after these calls depends on the UI update having completed (cancellation is still checked inside the lambdas), so post the updates instead. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01KCxH1zwDXLd9kfAAkcf6PZ
1 parent 3e65576 commit 70e4208

2 files changed

Lines changed: 9 additions & 9 deletions

File tree

‎src/ViewModels/Launcher.cs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -441,7 +441,7 @@ private void DispatchNotification(Models.Notification notification)
441441
{
442442
if (!Dispatcher.UIThread.CheckAccess())
443443
{
444-
Dispatcher.UIThread.Invoke(() => DispatchNotification(notification));
444+
Dispatcher.UIThread.Post(() => DispatchNotification(notification));
445445
return;
446446
}
447447

‎src/ViewModels/Repository.cs‎

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1182,7 +1182,7 @@ public void RefreshBranches()
11821182
var remotes = await new Commands.QueryRemotes(FullPath).GetResultAsync().ConfigureAwait(false);
11831183
var builder = BuildBranchTree(branches, remotes);
11841184

1185-
Dispatcher.UIThread.Invoke(() =>
1185+
Dispatcher.UIThread.Post(() =>
11861186
{
11871187
if (token.IsCancellationRequested)
11881188
return;
@@ -1218,7 +1218,7 @@ public void RefreshWorktrees()
12181218
{
12191219
var worktrees = await new Commands.Worktree(FullPath).ReadAllAsync().ConfigureAwait(false);
12201220
var cleaned = Worktree.Build(FullPath, worktrees);
1221-
Dispatcher.UIThread.Invoke(() => Worktrees = cleaned);
1221+
Dispatcher.UIThread.Post(() => Worktrees = cleaned);
12221222
});
12231223
}
12241224

@@ -1233,7 +1233,7 @@ public void RefreshTags()
12331233
Task.Run(async () =>
12341234
{
12351235
var tags = await new Commands.QueryTags(FullPath).GetResultAsync().ConfigureAwait(false);
1236-
Dispatcher.UIThread.Invoke(() =>
1236+
Dispatcher.UIThread.Post(() =>
12371237
{
12381238
if (token.IsCancellationRequested)
12391239
return;
@@ -1292,7 +1292,7 @@ public void RefreshCommits()
12921292
}
12931293
}
12941294

1295-
Dispatcher.UIThread.Invoke(() =>
1295+
Dispatcher.UIThread.Post(() =>
12961296
{
12971297
if (token.IsCancellationRequested)
12981298
return;
@@ -1318,7 +1318,7 @@ public void RefreshSubmodules()
13181318
{
13191319
if (_submodules.Count > 0)
13201320
{
1321-
Dispatcher.UIThread.Invoke(() =>
1321+
Dispatcher.UIThread.Post(() =>
13221322
{
13231323
Submodules = [];
13241324
VisibleSubmodules = BuildVisibleSubmodules();
@@ -1332,7 +1332,7 @@ public void RefreshSubmodules()
13321332
{
13331333
var submodules = await new Commands.QuerySubmodules(FullPath).GetResultAsync().ConfigureAwait(false);
13341334

1335-
Dispatcher.UIThread.Invoke(() =>
1335+
Dispatcher.UIThread.Post(() =>
13361336
{
13371337
bool hasChanged = _submodules.Count != submodules.Count;
13381338
if (!hasChanged)
@@ -1389,7 +1389,7 @@ public void RefreshWorkingCopyChanges()
13891389

13901390
changes.Sort((l, r) => Models.NumericSort.Compare(l.Path, r.Path));
13911391

1392-
Dispatcher.UIThread.Invoke(() =>
1392+
Dispatcher.UIThread.Post(() =>
13931393
{
13941394
if (token.IsCancellationRequested)
13951395
return;
@@ -1416,7 +1416,7 @@ public void RefreshStashes()
14161416
Task.Run(async () =>
14171417
{
14181418
var stashes = await new Commands.QueryStashes(FullPath).GetResultAsync().ConfigureAwait(false);
1419-
Dispatcher.UIThread.Invoke(() =>
1419+
Dispatcher.UIThread.Post(() =>
14201420
{
14211421
if (token.IsCancellationRequested)
14221422
return;

0 commit comments

Comments
 (0)