public async static Task Main()

in src/Worker.cs [28:106]


        public async static Task Main(string[] args)
        {
            RpcLogger.WriteSystemLog(
                LogLevel.Information,
                string.Format(PowerShellWorkerStrings.PowerShellWorkerVersion, typeof(Worker).Assembly.GetName().Version));

            var workerOptions = new WorkerOptions();

            var parser = new Parser(settings =>
            {
                settings.EnableDashDash = true;
                settings.IgnoreUnknownArguments = true;
            });
            parser.ParseArguments<WorkerArguments>(args)
                .WithParsed(workerArgs =>
                {
                    // TODO: Remove parsing old command-line arguments that are not prefixed with functions-<argumentname>
                    // for more information, see https://github.com/Azure/azure-functions-powershell-worker/issues/995
                    workerOptions.WorkerId = workerArgs.FunctionsWorkerId ?? workerArgs.WorkerId;
                    workerOptions.RequestId = workerArgs.FunctionsRequestId ?? workerArgs.RequestId;

                    if (!string.IsNullOrWhiteSpace(workerArgs.FunctionsUri))
                    {
                        try
                        {
                            // TODO: Update WorkerOptions to have a URI property instead of host name and port number
                            // for more information, see https://github.com/Azure/azure-functions-powershell-worker/issues/994
                            var uri = new Uri(workerArgs.FunctionsUri);
                            workerOptions.Host = uri.Host;
                            workerOptions.Port = uri.Port;
                        }
                        catch (UriFormatException formatEx)
                        {
                            var message = $"Invalid URI format: {workerArgs.FunctionsUri}. Error message: {formatEx.Message}";
                            throw new ArgumentException(message, nameof(workerArgs.FunctionsUri));
                        }
                    }
                    else
                    {
                        workerOptions.Host = workerArgs.Host;
                        workerOptions.Port = workerArgs.Port;
                    }

                    // Validate workerOptions
                    ValidateProperty("WorkerId", workerOptions.WorkerId);
                    ValidateProperty("RequestId", workerOptions.RequestId);
                    ValidateProperty("Host", workerOptions.Host);

                    if (workerOptions.Port <= 0)
                    {
                        throw new ArgumentException("Port number has not been initialized", nameof(workerOptions.Port));
                    }
                });

            // 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);
            WarmUpPowerShell(firstPowerShellInstance);

            var msgStream = new MessagingStream(workerOptions.Host, workerOptions.Port);
            var requestProcessor = new RequestProcessor(msgStream, firstPowerShellInstance, pwshVersion);

            // Send StartStream message
            var startedMessage = new StreamingMessage()
            {
                RequestId = workerOptions.RequestId,
                StartStream = new StartStream() { WorkerId = workerOptions.WorkerId }
            };

            msgStream.Write(startedMessage);
            await requestProcessor.ProcessRequestLoop();
        }