/// <summary> /// Start searching for a session of the given type. /// </summary> /// <param name="sessionType">The type of session to look for.</param> void FindSession(NetworkSessionType sessionType) { // create the new screen SearchResultsScreen searchResultsScreen = new SearchResultsScreen(sessionType); searchResultsScreen.ScreenManager = this.ScreenManager; ScreenManager.AddScreen(searchResultsScreen); // start the search try { IAsyncResult asyncResult = NetworkSession.BeginFind(sessionType, 1, null, null, null); // create the busy screen NetworkBusyScreen busyScreen = new NetworkBusyScreen( "Searching for a session...", asyncResult); busyScreen.OperationCompleted += searchResultsScreen.SessionsFound; ScreenManager.AddScreen(busyScreen); } catch (NetworkException ne) { const string message = "Failed searching for the session."; MessageBoxScreen messageBox = new MessageBoxScreen(message); messageBox.Accepted += FailedMessageBox; messageBox.Cancelled += FailedMessageBox; ScreenManager.AddScreen(messageBox); System.Console.WriteLine("Failed to search for session: " + ne.Message); } catch (GamerPrivilegeException gpe) { const string message = "You do not have permission to search for a session."; MessageBoxScreen messageBox = new MessageBoxScreen(message); messageBox.Accepted += FailedMessageBox; messageBox.Cancelled += FailedMessageBox; ScreenManager.AddScreen(messageBox); System.Console.WriteLine( "Insufficient privilege to search for session: " + gpe.Message); } }