From 99da99b13c68c5f2b82da2764d54b92b1b598657 Mon Sep 17 00:00:00 2001 From: czw <selecti@yeah.net> Date: 星期四, 03 七月 2025 11:32:16 +0800 Subject: [PATCH] 1 --- 2025年6月12日/AuxAllWCS/Build/Project/代码/界面事件.cs | 41 +++++++++++++++++++++++------------------ 1 files changed, 23 insertions(+), 18 deletions(-) diff --git "a/2025\345\271\2646\346\234\21012\346\227\245/AuxAllWCS/Build/Project/\344\273\243\347\240\201/\347\225\214\351\235\242\344\272\213\344\273\266.cs" "b/2025\345\271\2646\346\234\21012\346\227\245/AuxAllWCS/Build/Project/\344\273\243\347\240\201/\347\225\214\351\235\242\344\272\213\344\273\266.cs" index 58138e4..51d6749 100644 --- "a/2025\345\271\2646\346\234\21012\346\227\245/AuxAllWCS/Build/Project/\344\273\243\347\240\201/\347\225\214\351\235\242\344\272\213\344\273\266.cs" +++ "b/2025\345\271\2646\346\234\21012\346\227\245/AuxAllWCS/Build/Project/\344\273\243\347\240\201/\347\225\214\351\235\242\344\272\213\344\273\266.cs" @@ -387,15 +387,7 @@ try { #region [鑴氭湰][20250605212104026][涓氬姟閫昏緫.SocketServer] - var host = System.Net.Dns.GetHostEntry(System.Net.Dns.GetHostName()); - foreach (var ip in host.AddressList) - { - if (ip.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork) - { - Console.WriteLine($"ip= {ip.ToString()}"); - new TcpServer(ip.ToString()); - } - } + AutoThread.InvokeMethod(AutoThread.Instance, "TaskEverythingRun"); #endregion [鑴氭湰][20250605212104026][涓氬姟閫昏緫.SocketServer] } catch (Exception ex) @@ -771,6 +763,7 @@ } ExitJudgeStack.TryPop(out int exitJudgeVal); }); + /// <summary> /// 绋嬪簭鐗囨:Program1 /// 鎻忚堪: @@ -1061,12 +1054,13 @@ #endregion #region Http鏈嶅姟鐩戝惉 - private void HttpSvcListenerCallback(IAsyncResult ar) + private async void HttpSvcListenerCallback(IAsyncResult ar) { + System.Net.HttpListenerContext context = null; try { HttpSvcHost.BeginGetContext(HttpSvcListenerCallback, null); - System.Net.HttpListenerContext context = HttpSvcHost.EndGetContext(ar); + context = HttpSvcHost.EndGetContext(ar); System.Net.HttpListenerRequest request = context.Request; System.Net.HttpListenerResponse response = context.Response; switch (request.LocalEndPoint.ToString()) @@ -1076,21 +1070,28 @@ using (var reader = new System.IO.StreamReader(request.InputStream, System.Text.Encoding.UTF8)) { string requestJson = reader.ReadToEnd(); - - string respstr = HttpSvcListenerCallback_he(request.HttpMethod, request.Url.AbsolutePath, requestJson, out System.Net.HttpStatusCode statusCode); - + System.Net.HttpStatusCode statusCode = 0; + string respstr = await Task.Run(() => + { + return HttpSvcListenerCallback_he(request.HttpMethod, request.Url.AbsolutePath, requestJson, out statusCode); + }); string logContent = ""; logContent += $"\r\n[{request.HttpMethod}]{request.Url.AbsolutePath}"; logContent += $"\r\n[request]{requestJson}"; logContent += $"\r\n[response]{respstr}"; - Conn.榛樿鏃ュ織?.Info(logContent); + _ = Task.Run(() => + { + Conn.榛樿鏃ュ織?.Info(logContent); + }); byte[] bytstr = Encoding.UTF8.GetBytes(respstr); response.StatusCode = (int)statusCode; response.SendChunked = false; response.ContentLength64 = bytstr.Length; response.OutputStream.Write(bytstr, 0, bytstr.Length); - response.Close(); + // 寮傛鍐欏叆鍝嶅簲 + await response.OutputStream.WriteAsync(bytstr, 0, bytstr.Length); + } break; } @@ -1099,6 +1100,10 @@ catch (Exception ex) { Conn.榛樿鏃ュ織.Error(ex.ToString()); + } + finally + { + context?.Response.Close(); } } private System.String HttpSvcListenerCallback_he(System.String method, System.String path, System.String requestJson, out System.Net.HttpStatusCode statusCode) @@ -1167,12 +1172,12 @@ { switch (path) { - case "/inddddddddddddddddd": + case var _ when System.Text.RegularExpressions.Regex.IsMatch(path, @"\.(html|ico|js|css)(\?.*)?$", System.Text.RegularExpressions.RegexOptions.IgnoreCase): { statusCode = System.Net.HttpStatusCode.OK; // 澶嶅埗鍒癱ase 涓� //var _ when System.Text.RegularExpressions.Regex.IsMatch(path, @"\.(html|ico|js|css)(\?.*)?$", System.Text.RegularExpressions.RegexOptions.IgnoreCase) - var filePath = System.IO.Path.Combine("Static", path.Substring(1)); + var filePath = /*Directory.GetCurrentDirectory() + "\\Static" + "\\" + path.Substring(1);*/System.IO.Path.Combine(Directory.GetCurrentDirectory() + "\\Static", path.Substring(1)); return File.ReadAllText(filePath); } } -- Gitblit v1.9.1