internal void OnProcessExit() { _ProcessExited = true; _logger?.LogInformation("等待IProcessExitHandler任务执行完毕"); List <Task> tasks = new List <Task>(); lock (_missions) { foreach (var action in _missions) { try { tasks.Add(Task.Run(action)); } catch { } } _missions.Clear(); } Task.WaitAll(tasks.ToArray()); _logger?.LogInformation("准备断开网关"); try { var client = new NetClient(_microServiceHost.MasterGatewayAddress); client.WriteServiceData(new GatewayCommand { Type = CommandType.UnRegisterSerivce, Content = _microServiceHost.Id }); client.ReadServiceObject <InvokeResult>(); } catch (Exception ex) { _logger?.LogError(ex, ex.Message); } _logger?.LogInformation("等待事务托管中心事务清零"); while (_transactionDelegateCenter.List.Count > 0) { Thread.Sleep(1000); } _logger?.LogInformation("停止所有定时任务"); _scheduleTaskManager.StopTasks(); _safeTaskFactory?.WaitAll(); _logger?.LogInformation("等待客户端请求数清零"); //等待客户连接处理完毕 while (_microServiceHost.ClientConnected > 0) { Thread.Sleep(1000); } _logger?.LogInformation("客户端请求数为零"); Thread.Sleep(1000); }
private void CurrentDomain_ProcessExit(object sender, EventArgs e) { ProcessExited = true; _logger?.LogInformation("准备断开网关"); try { var client = new NetClient(_microServiceHost.MasterGatewayAddress); client.WriteServiceData(new GatewayCommand { Type = CommandType.UnRegisterSerivce, Content = _microServiceHost.Id }); client.ReadServiceObject <InvokeResult>(); } catch (Exception ex) { _logger?.LogError(ex, ex.Message); } _logger?.LogInformation("等待事务托管中心事务清零"); while (_transactionDelegateCenter.List.Count > 0) { Thread.Sleep(1000); } _logger?.LogInformation("停止所有定时任务"); _scheduleTaskManager.StopTasks(); _logger?.LogInformation("等待客户端请求数清零"); //等待客户连接处理完毕 while (_microServiceHost.ClientConnected > 0) { Thread.Sleep(1000); } _logger?.LogInformation("客户端请求数为零,当前进程退出"); Thread.Sleep(1000); }