Commit 6f29f030 张东亮

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

1 个父辈 4a497904
......@@ -38,11 +38,13 @@ namespace OnlineStore.Common
return false;
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));
smfResult = JsonHelper.DeserializeJsonToObject<SmfResult>(Encoding.UTF8.GetString(resp));
}
}
catch (Exception e)
{
LogUtil.info($"UploadJsonData:{api}" + e.ToString());
......@@ -54,12 +56,15 @@ namespace OnlineStore.Common
string api = "/api/translation/resource?type=" + DeviceType;
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);
var jsondata = Encoding.UTF8.GetString(resp);
return JsonConvert.DeserializeObject<List<SmfLangData>>(jsondata);
}
}
catch (Exception e)
{
LogUtil.info($"DownloadLngData:{api}" + e.ToString());
......
此文件类型无法预览
......@@ -80,13 +80,16 @@ namespace DeviceLibrary
{
num--;
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;
}
}
}
throw new Exception("算法服务器文件打开失败");
}
}catch(Exception ex)
......
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!