diff --git a/src/Worker.cs b/src/Worker.cs index e11b501c..7764e867 100644 --- a/src/Worker.cs +++ b/src/Worker.cs @@ -79,9 +79,13 @@ public async static Task Main(string[] args) } }); + // This must be done before the first Runspace is created, to avoid the creation of a thread by the upgrade checker + SetVersionUpgradeOptOut(); + // Create the very first Runspace so the debugger has the target to attach to. // This PowerShell instance is shared by the first PowerShellManager instance created in the pool, // and the dependency manager (used to download dependent modules if needed). + var firstPowerShellInstance = Utils.NewPwshInstance(); var pwshVersion = Utils.GetPowerShellVersion(firstPowerShellInstance); LogPowerShellVersion(pwshVersion); @@ -101,6 +105,15 @@ public async static Task Main(string[] args) await requestProcessor.ProcessRequestLoop(); } + private static void SetVersionUpgradeOptOut() + { + string checkForUpgrade = Environment.GetEnvironmentVariable("AZUREPS_CHECK_FOR_UPGRADE"); + if (string.IsNullOrWhiteSpace(checkForUpgrade)) + { + Environment.SetEnvironmentVariable("AZUREPS_CHECK_FOR_UPGRADE", "False"); + } + } + // Warm up the PowerShell instance so that the subsequent function load and invocation requests are faster private static void WarmUpPowerShell(System.Management.Automation.PowerShell firstPowerShellInstance) {