/* * The function will rapidly ask the server to send the rooms list so it will be updated // Might be a thread * input: none * output: none */ private void RefreshRoomsList() { GetRoomsResponse response = (GetRoomsResponse)Communicator.Communicate(new GetRoomsRequest()); availiableRoom = new Dictionary <string, string>(); if (response.status == 1) { if (!response.rooms.Equals("")) { string[] rooms = response.rooms.Split(','); for (int i = 0; i < rooms.Length; i++) { string[] parts = rooms[i].Split(':'); availiableRoom.Add(parts[0], parts[1]); } } UpdateRoomsListGrid(); } }
private void Refresh() { while (!hasEntered) { Dispatcher.BeginInvoke(new Action(() => { room_list_panel.Children.Clear(); })); string answer = Communicator.Send("", (byte)ReqCode.GETROOMS); answer = answer.Substring(answer.IndexOf('{'), answer.IndexOf('}') - 4); GetRoomsResponse response = JsonConvert.DeserializeObject <GetRoomsResponse>(answer); string[] rooms = response.rooms.Split(','); if (rooms[0] == "" && rooms.Length == 1) { goto label; } Dispatcher.BeginInvoke(new Action(() => { foreach (string room in rooms) { Button button = new Button { Content = room.Substring(0, room.IndexOf(':')), FontSize = 20, FontFamily = new FontFamily("Tempus Sans ITC"), Background = Brushes.Blue, Margin = new Thickness(10), Cursor = System.Windows.Input.Cursors.Hand }; button.Click += Room_Choose_Click; Communicator.roomId = int.Parse(room.Substring(room.IndexOf(':') + 1)); room_list_panel.Children.Add(button); } })); label: Thread.Sleep(3000); } }