private async Task <bool> LoginTask(string username, string password) { var values = new Dictionary <string, string>(); values.Add("user", username); values.Add("pwd", password); values.Add("action", "login"); string reqUri = "index.php"; string responseString = await SendRequest.POST(reqUri, values); if (string.IsNullOrEmpty(responseString)) { SessionId = "Login error"; return(false); } var doc = new HtmlDocument(); doc.LoadHtml(responseString); HtmlNode node = doc.DocumentNode.SelectSingleNode("//form[@name='frm_gate']"); if (node != null) { // Login success // Get sessionId var cookies = Client.CookieContainer.GetCookies(Client.GetUri("index.php")); var sessionId = cookies["PHPSESSID"]; SessionId = "Online"; //Task tsk = LoadStatus(); //OpenWindow_FilesAndPrograms(); //OpenWindow_RunningSoftware(); //OpenWindow_Logs(); //await UpdateRoute(); //await tsk; //Thread t = new Thread(AutoRefreshStatus); //t.SetApartmentState(ApartmentState.STA); //t.IsBackground = true; //t.Start(); return(true); } else { // Login fail SessionId = "Login fail"; return(false); } }