private void goToGameView(object obj) { if (LobbyViewModel != null) { LobbyViewModel.Dispose(); LobbyViewModel = null; } Task.Delay(500).ContinueWith(_ => { if (GameViewModel != null) { GameViewModel.Dispose(); GameViewModel = null; } GameViewModel = new GameViewModel((string)obj); App.Current.Dispatcher.Invoke(delegate { SubChannels.Remove(_subChannels.SingleOrDefault(i => i.id == (Constants.LOBBY_CHANNEL + Lobbyname))); MessageChannel gameChannel = new MessageChannel(Constants.GAME_CHANNEL, true, false); if (!SubChannels.Contains(gameChannel)) { SubChannels.Add(gameChannel); } ChangeChannel(Constants.GAME_CHANNEL); }); SwitchView = Views.Game; IsInGame = true; }); }
private void goToLobbyView(object lobbyData) { IsNotInLobby = false; Dictionary <string, string> data = new Dictionary <string, string>((Dictionary <string, string>)lobbyData); if (LobbyViewModel != null) { LobbyViewModel.Dispose(); LobbyViewModel = null; } LobbyViewModel = new LobbyViewModel(data["lobbyName"], data["mode"]); this.Lobbyname = data["lobbyName"]; string lobbyChannel = Constants.LOBBY_CHANNEL + this.Lobbyname; SwitchView = Views.Lobby; Application.Current.Dispatcher.Invoke(delegate { SubChannels.Add(new MessageChannel(lobbyChannel, true, true)); }); ChangeChannel(lobbyChannel); }