mirror of
				https://github.com/2dust/v2rayN.git
				synced 2025-11-04 06:22:52 +00:00 
			
		
		
		
	Merge pull request #4711 from hxdhttk/hxdhttk/mixedStdErr
Fix misleading "Cannot mix synchronous and asynchronous operation on process stream." logs.
This commit is contained in:
		
						commit
						c03c98157f
					
				
					 1 changed files with 15 additions and 3 deletions
				
			
		| 
						 | 
					@ -156,7 +156,7 @@ namespace v2rayN.Handler
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        #region Private
 | 
					        #region Private
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        private string CoreFindexe(CoreInfo coreInfo)
 | 
					        private string CoreFindExe(CoreInfo coreInfo)
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
            string fileName = string.Empty;
 | 
					            string fileName = string.Empty;
 | 
				
			||||||
            foreach (string name in coreInfo.coreExes)
 | 
					            foreach (string name in coreInfo.coreExes)
 | 
				
			||||||
| 
						 | 
					@ -266,7 +266,7 @@ namespace v2rayN.Handler
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
            try
 | 
					            try
 | 
				
			||||||
            {
 | 
					            {
 | 
				
			||||||
                string fileName = CoreFindexe(coreInfo);
 | 
					                string fileName = CoreFindExe(coreInfo);
 | 
				
			||||||
                if (Utils.IsNullOrEmpty(fileName))
 | 
					                if (Utils.IsNullOrEmpty(fileName))
 | 
				
			||||||
                {
 | 
					                {
 | 
				
			||||||
                    return null;
 | 
					                    return null;
 | 
				
			||||||
| 
						 | 
					@ -286,6 +286,8 @@ namespace v2rayN.Handler
 | 
				
			||||||
                        StandardErrorEncoding = displayLog ? Encoding.UTF8 : null,
 | 
					                        StandardErrorEncoding = displayLog ? Encoding.UTF8 : null,
 | 
				
			||||||
                    }
 | 
					                    }
 | 
				
			||||||
                };
 | 
					                };
 | 
				
			||||||
 | 
					                var startUpErrorMessage = new StringBuilder();
 | 
				
			||||||
 | 
					                var startUpSuccessful = false;
 | 
				
			||||||
                if (displayLog)
 | 
					                if (displayLog)
 | 
				
			||||||
                {
 | 
					                {
 | 
				
			||||||
                    proc.OutputDataReceived += (sender, e) =>
 | 
					                    proc.OutputDataReceived += (sender, e) =>
 | 
				
			||||||
| 
						 | 
					@ -302,6 +304,11 @@ namespace v2rayN.Handler
 | 
				
			||||||
                        {
 | 
					                        {
 | 
				
			||||||
                            string msg = e.Data + Environment.NewLine;
 | 
					                            string msg = e.Data + Environment.NewLine;
 | 
				
			||||||
                            update(false, msg);
 | 
					                            update(false, msg);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                            if (!startUpSuccessful)
 | 
				
			||||||
 | 
					                            {
 | 
				
			||||||
 | 
					                                startUpErrorMessage.Append(msg);
 | 
				
			||||||
 | 
					                            }
 | 
				
			||||||
                        }
 | 
					                        }
 | 
				
			||||||
                    };
 | 
					                    };
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
| 
						 | 
					@ -314,7 +321,12 @@ namespace v2rayN.Handler
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                if (proc.WaitForExit(1000))
 | 
					                if (proc.WaitForExit(1000))
 | 
				
			||||||
                {
 | 
					                {
 | 
				
			||||||
                    throw new Exception(displayLog ? proc.StandardError.ReadToEnd() : "启动进程失败并退出 (Failed to start the process and exited)");
 | 
					                    proc.CancelErrorRead();
 | 
				
			||||||
 | 
					                    throw new Exception(displayLog ? startUpErrorMessage.ToString() : "启动进程失败并退出 (Failed to start the process and exited)");
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					                else
 | 
				
			||||||
 | 
					                {
 | 
				
			||||||
 | 
					                    startUpSuccessful = true;
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                LazyConfig.Instance.AddProcess(proc.Handle);
 | 
					                LazyConfig.Instance.AddProcess(proc.Handle);
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in a new issue