private async Task <int> Run(HostCommandContext context, string pipeName, long maxMemory, int affinityMask, int maxCpu) { var currentProcess = SDProcess.GetCurrentProcess(); var logger = context.ServiceProvider.GetService <ILoggerFactory>().CreateLogger <HostProcessImpl>(); logger.HostProcessStart(currentProcess.Id); string name = "pihost." + currentProcess.Id; var limits = new IsolationLimits(maxMemory, maxCpu, affinityMask); if (limits.IsAnyEnabled) { s_jobObject = new JobObject(name); s_jobObject.AddProcess(currentProcess); s_jobObject.Enable(limits, (l, v) => logger.ProcessLimitSet(l, v)); } var host = new IpcServiceHostBuilder(context.ServiceProvider) .AddNamedPipeEndpoint <IHostProcess>(name, pipeName, includeFailureDetailsInResponse: true) .Build(); logger.IpcServiceHostStarting(pipeName); context.SetStartComplete(); await host.RunAsync(context.Token).ConfigureAwait(false); return(0); }