private void AutoUpdateToServer() { textBox1.Text = "Starting...\n"; string baseHost = ConfigurationManager.AppSettings["SERVERURL"]; string clientCode = ConfigurationManager.AppSettings["CLIENTCODE"]; try { //WebRequest request = WebRequest.Create("http://google.com/"); //request.Timeout = Timeout.Infinite; ////request.KeepAlive = true; //HttpWebResponse response = (HttpWebResponse)request.GetResponse(); //if (response == null || response.StatusCode != HttpStatusCode.OK) //{ // Console.WriteLine("Hiện không thể kết nối máy chủ. \n Chương trình sẽ chạy với dữ liệu offline cho đến khi có kết nối với máy chủ.\n Hãy kiểm tra kết nối internet và [Thiết lập máy trạm]"); //} //else //{ // Đồng bộ user textBox1.Text += "Sync User ...\n"; BBLUser userData = new BBLUser(); userData.ServiceUpdate(baseHost); textBox1.Text += "Sync user is success n"; textBox1.Text += "Sync Info ...\n"; // Đồng bộ Info BBLInfo infoData = new BBLInfo(); infoData.ServiceUpdate(baseHost); textBox1.Text += "Sync info is success n"; textBox1.Text += "Sync client ...\n"; // Đồng bộ BBLClient BBLClient clientData = new BBLClient(); clientData.ServiceUpdate(baseHost); textBox1.Text += "Sync client is success n"; textBox1.Text += "Sync Consultant ...\n"; // Đồng bộ BBLConsultant BBLConsultant consultantData = new BBLConsultant(); consultantData.ServiceUpdate(baseHost); //} textBox1.Text += "finish \n"; } catch (Exception ex) { Console.WriteLine(ex.Message); Console.WriteLine(ex.StackTrace); Console.WriteLine(ex.Source); textBox1.Text += "Error " + ex.Message; } }
private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e) { panelDongBo.Invoke((Action)(() => { panelDongBo.Visible = true; progressBar1.Value = progressBar1.Minimum; })); string baseHost = ConfigurationManager.AppSettings["SERVERURL"]; string clientCode = ConfigurationManager.AppSettings["CLIENTCODE"]; try { progressBar1.Invoke((Action)(() => progressBar1.Value = 1)); worker.ReportProgress(1); // Đồng bộ user BBLUser userData = new BBLUser(); userData.ServiceUpdate(baseHost); progressBar1.Invoke((Action)(() => progressBar1.Value = 2)); worker.ReportProgress(2); // Đồng bộ Info BBLInfo infoData = new BBLInfo(); infoData.ServiceUpdate(baseHost); progressBar1.Invoke((Action)(() => progressBar1.Value = 6)); worker.ReportProgress(3); // Đồng bộ BBLClient BBLClient clientData = new BBLClient(); clientData.ServiceUpdate(baseHost); progressBar1.Invoke((Action)(() => progressBar1.Value = 8)); worker.ReportProgress(4); // Đồng bộ BBLConsultant BBLConsultant consultantData = new BBLConsultant(); consultantData.ServiceUpdate(baseHost); progressBar1.Invoke((Action)(() => progressBar1.Value = 10)); worker.ReportProgress(5); } catch (Exception ex) { MessageBox.Show(ex.Message + ex.StackTrace); } }