mirror of
https://github.com/aphrody-labs/PowerShell.git
synced 2026-10-17 12:45:47 +00:00
Create JumpList in background thread to improve performance (#6985)
* Perform JumpList creation in background thread to improve performance when pwsh owns the window (i.e. when the Jumplist has to be created) * Move JumpList creation to a later stage to allow for more code that might make it exit earlier as suggested in PR review by @iSazonov
This commit is contained in:
1 parent
b66013d11c
commit
f54085f8a3
2 files changed
+13
-5
No files matched your search
@@ -12,7 +12,8 @@ namespace Microsoft.PowerShell
|
||||
{
|
||||
internal static void CreateElevatedEntry(string title)
|
||||
{
|
||||
// check startupInfo to know if the current shell owns a window before proceeding
|
||||
// Check startupInfo first to know if the current shell is interactive and owns a window before proceeding
|
||||
// This check is fast (less than 1ms) and allows for quick-exit
|
||||
GetStartupInfo(out StartUpInfo startupInfo);
|
||||
var STARTF_USESHOWWINDOW = 0x00000001;
|
||||
var SW_HIDE = 0;
|
||||
|
||||
@@ -26,6 +26,7 @@ using System.Management.Automation.Language;
|
||||
using Dbg = System.Management.Automation.Diagnostics;
|
||||
using ConsoleHandle = Microsoft.Win32.SafeHandles.SafeFileHandle;
|
||||
using System.Management.Automation.Tracing;
|
||||
using System.Threading.Tasks;
|
||||
#if LEGACYTELEMETRY
|
||||
using Microsoft.PowerShell.Telemetry.Internal;
|
||||
#endif
|
||||
@@ -120,10 +121,6 @@ namespace Microsoft.PowerShell
|
||||
}
|
||||
#endif
|
||||
|
||||
#if !UNIX
|
||||
Microsoft.PowerShell.TaskbarJumpList.CreateElevatedEntry(ConsoleHostStrings.RunAsAdministrator);
|
||||
#endif
|
||||
|
||||
// put PSHOME in front of PATH so that calling `powershell` within `powershell` always starts the same running version
|
||||
string path = Environment.GetEnvironmentVariable("PATH");
|
||||
if (path != null)
|
||||
@@ -214,6 +211,16 @@ namespace Microsoft.PowerShell
|
||||
return ExitCodeBadCommandLineParameter;
|
||||
}
|
||||
|
||||
#if !UNIX
|
||||
// Creating a JumpList entry takes around 55ms when the PowerShell process is interactive and
|
||||
// owns the current window (otherwise it does a fast exit anyway). Since there is no 'GET' like API,
|
||||
// we always have to execute this call because we do not know if it has been created yet.
|
||||
// The JumpList does persist as long as the filepath of the executable does not change but there
|
||||
// could be disruptions to it like e.g. the bi-annual Windows update, we decided to
|
||||
// not over-optimize this and always create the JumpList as a non-blocking background task instead.
|
||||
Task.Run(() => TaskbarJumpList.CreateElevatedEntry(ConsoleHostStrings.RunAsAdministrator));
|
||||
#endif
|
||||
|
||||
// First check for and handle PowerShell running in a server mode.
|
||||
if (s_cpp.ServerMode)
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user