Commit 6f29f030 张东亮

通讯使用using,避免异常不释放端口问题

1 个父辈 4a497904
...@@ -35,13 +35,15 @@ namespace OnlineStore.Common ...@@ -35,13 +35,15 @@ namespace OnlineStore.Common
{ {
smfResult = new SmfResult(); smfResult = new SmfResult();
if (string.IsNullOrEmpty(server)) if (string.IsNullOrEmpty(server))
return false; return false;
try try
{ {
MyWebClient wc = new MyWebClient(10 * 1000); using (MyWebClient wc = new MyWebClient(10 * 1000))
wc.Headers.Add("Content-Type", "application/json;charset=UTF-8"); {
var resp = wc.UploadData(server + api, Encoding.UTF8.GetBytes(json)); wc.Headers.Add("Content-Type", "application/json;charset=UTF-8");
smfResult = JsonHelper.DeserializeJsonToObject<SmfResult>(Encoding.UTF8.GetString(resp)); var resp = wc.UploadData(server + api, Encoding.UTF8.GetBytes(json));
smfResult = JsonHelper.DeserializeJsonToObject<SmfResult>(Encoding.UTF8.GetString(resp));
}
} }
catch (Exception e) catch (Exception e)
{ {
...@@ -54,11 +56,14 @@ namespace OnlineStore.Common ...@@ -54,11 +56,14 @@ namespace OnlineStore.Common
string api = "/api/translation/resource?type=" + DeviceType; string api = "/api/translation/resource?type=" + DeviceType;
try try
{ {
MyWebClient wc = new MyWebClient(10 * 1000); using (MyWebClient wc = new MyWebClient(10 * 1000))
wc.Headers.Add("Content-Type", "application/json;charset=UTF-8"); {
var resp = wc.DownloadData(server + api); wc.Headers.Add("Content-Type", "application/json;charset=UTF-8");
var jsondata = Encoding.UTF8.GetString(resp); var resp = wc.DownloadData(server + api);
return JsonConvert.DeserializeObject<List<SmfLangData>>(jsondata); var jsondata = Encoding.UTF8.GetString(resp);
return JsonConvert.DeserializeObject<List<SmfLangData>>(jsondata);
}
} }
catch (Exception e) catch (Exception e)
{ {
......
此文件类型无法预览
...@@ -80,12 +80,15 @@ namespace DeviceLibrary ...@@ -80,12 +80,15 @@ namespace DeviceLibrary
{ {
num--; num--;
Thread.Sleep(1000); Thread.Sleep(1000);
MyWebClient myWebClient = new MyWebClient(webclienttimeout); using (MyWebClient myWebClient = new MyWebClient(webclienttimeout))
string text2 = myWebClient.DownloadString(visionUrl + "/alive");
if (text2.Trim() == "\"1\"")
{ {
return; string text2 = myWebClient.DownloadString(visionUrl + "/alive");
if (text2.Trim() == "\"1\"")
{
return;
}
} }
} }
throw new Exception("算法服务器文件打开失败"); throw new Exception("算法服务器文件打开失败");
} }
......
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!