Lấy API Url thông qua tham số của Constructor

This commit is contained in:
Le Chau 2020-06-25 09:46:30 +07:00
parent b877a1493e
commit 444b58721f

View File

@ -1,10 +1,5 @@
using System; using System;
using System.Text;
using System.Windows.Forms; using System.Windows.Forms;
using System.IO;
using System.Net;
using System.Web.Script.Serialization;
using System.Diagnostics.SymbolStore;
using System.Threading; using System.Threading;
using Newtonsoft.Json; using Newtonsoft.Json;
using System.Net.Http; using System.Net.Http;
@ -13,7 +8,7 @@ namespace AIParkingApplication
{ {
public partial class Statistic : UserControl public partial class Statistic : UserControl
{ {
private readonly HttpClient client = new HttpClient { BaseAddress = new Uri("http://192.168.1.123:80/"), Timeout = TimeSpan.FromMilliseconds(5000) }; private readonly HttpClient client;
Label lblLoaiXe; Label lblLoaiXe;
Label lblXeMay; Label lblXeMay;
@ -22,10 +17,11 @@ namespace AIParkingApplication
Label lblSoLuongXeMay; Label lblSoLuongXeMay;
Label lblSoLuongOto; Label lblSoLuongOto;
public Statistic() public Statistic(string apiUrl)
{ {
InitializeComponent(); InitializeComponent();
Thread thrStatistics = new Thread(new ThreadStart(GetStatistic)); Thread thrStatistics = new Thread(new ThreadStart(GetStatistic));
client = new HttpClient { BaseAddress = new Uri(apiUrl), Timeout = TimeSpan.FromMilliseconds(5000) };
thrStatistics.IsBackground = true; thrStatistics.IsBackground = true;
thrStatistics.Start(); thrStatistics.Start();
} }