SmallRefactor: Đưa HttpClient ra ngoài vòng lặp tránh bị gọi quá nhiều lần

This commit is contained in:
Le Chau 2020-06-25 09:33:57 +07:00
parent a61195ca03
commit 853c49969d

View File

@ -14,6 +14,7 @@ namespace AIParkingApplication
public partial class Statistic : UserControl
{
private const string AIPARKING_CLIENT_HTTP_API_REQUEST = "http://{0}:{1}{2}";
private readonly HttpClient client = new HttpClient { BaseAddress = new Uri("http://192.168.1.123:80/"), Timeout = TimeSpan.FromMilliseconds(5000) };
Label lblLoaiXe;
Label lblXeMay;
@ -42,8 +43,6 @@ namespace AIParkingApplication
private async void GETDataFromServer()
{
try
{
using (var client = new HttpClient { BaseAddress = new Uri("http://192.168.1.123:80/"), Timeout = TimeSpan.FromMilliseconds(5000) })
{
HttpResponseMessage response = await client.GetAsync("/api/statistics");
response.EnsureSuccessStatusCode();
@ -64,7 +63,7 @@ namespace AIParkingApplication
{
lblVehicleTotalOut.Text = vehicle.TotelOut;
}));
}
}
catch (Exception ex)
{