Skip to content

Commit 6a3d1cc

Browse files
authored
Code Quality: Faster background launch at Windows startup (#14464)
1 parent 9368719 commit 6a3d1cc

File tree

2 files changed

+18
-8
lines changed

2 files changed

+18
-8
lines changed

src/Files.App/App.xaml.cs

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -135,17 +135,25 @@ async Task ActivateAsync()
135135

136136
_ = MainWindow.Instance.InitializeApplicationAsync(appActivationArguments.Data);
137137
}
138-
139-
await AppLifecycleHelper.InitializeAppComponentsAsync();
140-
141-
if (isStartupTask && isLeaveAppRunning)
138+
else
142139
{
143-
// Create a system tray icon when initialization is done
140+
// Create a system tray icon
144141
SystemTrayIcon = new SystemTrayIcon().Show();
145-
App.Current.Exit();
142+
143+
// Sleep current instance
144+
Program.Pool = new(0, 1, $"Files-{ApplicationService.AppEnvironment}-Instance");
145+
146+
Thread.Yield();
147+
148+
if (Program.Pool.WaitOne())
149+
{
150+
// Resume the instance
151+
Program.Pool.Dispose();
152+
Program.Pool = null;
153+
}
146154
}
147-
else
148-
await AppLifecycleHelper.CheckAppUpdate();
155+
156+
await AppLifecycleHelper.InitializeAppComponentsAsync();
149157
}
150158
}
151159

src/Files.App/Helpers/Application/AppLifecycleHelper.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ await Task.WhenAll(
5252

5353
FileTagsHelper.UpdateTagsDb();
5454

55+
await CheckAppUpdate();
56+
5557
static Task OptionalTaskAsync(Task task, bool condition)
5658
{
5759
if (condition)

0 commit comments

Comments
 (0)