From cc92f80a45a834b5474f0af52e97ad5b9d026fe6 Mon Sep 17 00:00:00 2001 From: DucDangAnh Date: Mon, 29 Jun 2020 15:19:36 +0700 Subject: [PATCH] Util - use static HttpClient httpClientEngine as field. --- AIParkingApplication/Util.cs | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/AIParkingApplication/Util.cs b/AIParkingApplication/Util.cs index 9195211..20d8ead 100644 --- a/AIParkingApplication/Util.cs +++ b/AIParkingApplication/Util.cs @@ -10,6 +10,8 @@ namespace AIParkingApplication { public static class Util { + private static HttpClient httpClientEngine = new HttpClient { BaseAddress = new Uri("http://localhost:8080/"), Timeout = TimeSpan.FromMilliseconds(5000) }; + public static bool IsPingable(string destinationIPAddress, out long pingTime, int timeOut = UtilConstant.PING_TIMEOUT_MS) { var pingTask = Task.Factory.StartNew(async () => @@ -55,19 +57,16 @@ namespace AIParkingApplication string plateImageBase64 = Convert.ToBase64String(plateImage.ToBytes()); try { - using (var client = new HttpClient { BaseAddress = new Uri("http://localhost:8080/"), Timeout = TimeSpan.FromMilliseconds(5000) }) + var request = new PlateRequestEngineModel { - var request = new PlateRequestEngineModel - { - Img64 = plateImageBase64, - Mode = plateType == PlateType.Square ? "square" : "long", - Display = "full" - }; - HttpResponseMessage response = await client.PostAsJsonAsync("/get-from-frame", request); - response.EnsureSuccessStatusCode(); - var ocrResult = await response.Content.ReadAsAsync(); - return ocrResult; - } + Img64 = plateImageBase64, + Mode = plateType == PlateType.Square ? "square" : "long", + Display = "full" + }; + HttpResponseMessage response = await httpClientEngine.PostAsJsonAsync("/get-from-frame", request); + response.EnsureSuccessStatusCode(); + var ocrResult = await response.Content.ReadAsAsync(); + return ocrResult; } catch (Exception ex) {