truyền chu kì lấy thống kê qua tham số của constructor thay vì constant như trước

This commit is contained in:
Le Chau 2020-06-25 10:21:40 +07:00
parent a7fe049f15
commit 8f8f5343e9
2 changed files with 4 additions and 4 deletions

View File

@ -9,7 +9,5 @@
#endregion #endregion
public const string CAMERA_FAILED_IMAGE_PATH = @"Images\CantConnectCamera.jpg"; public const string CAMERA_FAILED_IMAGE_PATH = @"Images\CantConnectCamera.jpg";
public const int TIME_TO_GET_STATISTIC_INFO = 60;
} }
} }

View File

@ -10,6 +10,7 @@ namespace AIParkingApplication
{ {
private readonly HttpClient client; private readonly HttpClient client;
private readonly Thread thrStatistics; private readonly Thread thrStatistics;
private int timeCycle;
Label lblLoaiXe; Label lblLoaiXe;
Label lblXeMay; Label lblXeMay;
@ -18,9 +19,10 @@ namespace AIParkingApplication
Label lblSoLuongXeMay; Label lblSoLuongXeMay;
Label lblSoLuongOto; Label lblSoLuongOto;
public Statistic(string apiUrl) public Statistic(string apiUrl, int timeCycle_Sec = 1)
{ {
InitializeComponent(); InitializeComponent();
timeCycle = timeCycle_Sec; ;
client = new HttpClient { BaseAddress = new Uri(apiUrl), Timeout = TimeSpan.FromMilliseconds(5000) }; client = new HttpClient { BaseAddress = new Uri(apiUrl), Timeout = TimeSpan.FromMilliseconds(5000) };
thrStatistics = new Thread(new ThreadStart(GetStatistic)) { IsBackground = true }; thrStatistics = new Thread(new ThreadStart(GetStatistic)) { IsBackground = true };
thrStatistics.Start(); thrStatistics.Start();
@ -31,7 +33,7 @@ namespace AIParkingApplication
while (true) while (true)
{ {
GETDataFromServer(); GETDataFromServer();
Thread.Sleep(AppConstant.TIME_TO_GET_STATISTIC_INFO * 1000); Thread.Sleep(timeCycle * 1000);
} }
} }