Fix process priority for logon startup task set to BelowNormal by default#4283
Fix process priority for logon startup task set to BelowNormal by default#4283
Conversation
The default priority for Windows Task Scheduler tasks is Low (7), which causes Flow Launcher to be sluggish when other processes are consuming CPU. Explicitly set the task priority to Normal when creating the logon startup task. Also update CheckLogonTask() to recreate the task if the priority is not Normal, so existing users with the incorrect priority get automatically fixed on next startup. Co-authored-by: Jack251970 <53996452+Jack251970@users.noreply.github.com>
|
🥷 Code experts: jjw24 jjw24 has most 👩💻 activity in the files. See details
Activity based on git-commit:
Knowledge based on git-blame: ✨ Comment |
|
Be a legend 🏆 by adding a before and after screenshot of the changes you made, especially if they are around UI/UX. |
There was a problem hiding this comment.
Pull request overview
Adjusts the Scheduled Task configuration used for “logon task” auto-start so Flow Launcher runs at a normal process priority (avoiding sluggish behavior reported when the task defaults to BelowNormal).
Changes:
- Set
TaskDefinition.Settings.PrioritytoProcessPriorityClass.Normalwhen creating the logon startup task. - Detect non-normal task priority during startup checks and recreate the logon task when needed.
Comments suppressed due to low confidence (1)
Flow.Launcher/Helper/AutoStartup.cs:74
- When
needsRecreationis true, the return values fromUnscheduleLogonTask()/ScheduleLogonTask()are ignored, butScheduleLogonTask()swallows exceptions and returnsfalseon failure. This means task recreation can fail silently whileCheckLogonTask()still returnstrue, so the UI may think auto-start is enabled and the app may keep retrying on every launch. Consider propagating failures here (e.g., throw when unschedule/schedule returns false, or return false fromCheckLogonTask()so callers can surface the error and/or disable the setting).
var needsRecreation = !action.Equals(Constant.ExecutablePath, StringComparison.OrdinalIgnoreCase)
|| task.Definition.Settings.Priority != ProcessPriorityClass.Normal;
if (needsRecreation)
{
UnscheduleLogonTask();
ScheduleLogonTask();
}
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
📝 WalkthroughWalkthroughThis change modifies the AutoStartup helper to explicitly set Normal priority for scheduled logon tasks and recreate the task if the priority is not Normal, addressing a performance regression where the process runs at Low priority by default. Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 minutes Suggested reviewers
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
Flow.Launcher/Helper/AutoStartup.cs (1)
68-74:needsRecreationlogic is correct — minor note on unnecessary delete when only priority differs.When the executable path matches but only the priority is stale,
UnscheduleLogonTask()still deletes the task beforeScheduleLogonTask()re-creates it. SinceRegisterTaskDefinitionoverwrites an existing task by name, the initial unschedule is redundant in the priority-only-mismatch case and creates a brief window (milliseconds) where no startup task is registered. It's harmless in practice, but the delete step could be skipped andScheduleLogonTask()called directly to update in-place.♻️ Optional simplification
- var needsRecreation = !action.Equals(Constant.ExecutablePath, StringComparison.OrdinalIgnoreCase) - || task.Definition.Settings.Priority != ProcessPriorityClass.Normal; - if (needsRecreation) - { - UnscheduleLogonTask(); - ScheduleLogonTask(); - } + var pathChanged = !action.Equals(Constant.ExecutablePath, StringComparison.OrdinalIgnoreCase); + var priorityWrong = task.Definition.Settings.Priority != ProcessPriorityClass.Normal; + if (pathChanged || priorityWrong) + { + if (pathChanged) + { + UnscheduleLogonTask(); + } + ScheduleLogonTask(); + }🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@Flow.Launcher/Helper/AutoStartup.cs` around lines 68 - 74, The current logic computes needsRecreation and always calls UnscheduleLogonTask() before ScheduleLogonTask(), which unnecessarily deletes the existing task when only Priority differs; change the flow so that when needsRecreation is true but the action equals Constant.ExecutablePath (i.e., only task.Definition.Settings.Priority != ProcessPriorityClass.Normal) skip UnscheduleLogonTask() and call ScheduleLogonTask() directly so RegisterTaskDefinition can overwrite in-place; adjust the condition around UnscheduleLogonTask() to only delete when action differs from Constant.ExecutablePath.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@Flow.Launcher/Helper/AutoStartup.cs`:
- Around line 68-74: The current logic computes needsRecreation and always calls
UnscheduleLogonTask() before ScheduleLogonTask(), which unnecessarily deletes
the existing task when only Priority differs; change the flow so that when
needsRecreation is true but the action equals Constant.ExecutablePath (i.e.,
only task.Definition.Settings.Priority != ProcessPriorityClass.Normal) skip
UnscheduleLogonTask() and call ScheduleLogonTask() directly so
RegisterTaskDefinition can overwrite in-place; adjust the condition around
UnscheduleLogonTask() to only delete when action differs from
Constant.ExecutablePath.
Follow on with #3218,
The default value of
task.Definition.Settings.Priorityseems to beBelowNormalwhich is used for background services.Now we use normal for it.
Fix #4281.
Summary by cubic
Fixes sluggish responsiveness when Flow Launcher starts via the Windows logon task by setting the task’s process priority to Normal and auto-recreating it if the priority is wrong. This addresses Task Scheduler’s default BelowNormal/Low priority, fixes existing installs on next start, and closes #4281 (follow-up to #3218).
Written for commit fc3860c. Summary will update on new commits.