/// <summary>
        /// Callback to receive the network-session search results from quick-match.
        /// </summary>
        void QuickMatchSearchCompleted(object sender, OperationCompletedEventArgs e)
        {
            try
            {
                AvailableNetworkSessionCollection availableSessions =
                    NetworkSession.EndFind(e.AsyncResult);
                if ((availableSessions != null) && (availableSessions.Count > 0))
                {
                    // join the session
                    try
                    {
                        IAsyncResult asyncResult = NetworkSession.BeginJoin(
                            availableSessions[0], null, null);

                        // create the busy screen
                        NetworkBusyScreen busyScreen = new NetworkBusyScreen(
                            "Joining the session...", asyncResult);
                        busyScreen.OperationCompleted += QuickMatchSessionJoined;
                        ScreenManager.AddScreen(busyScreen);
                    }
                    catch (NetworkException ne)
                    {
                        const string     message    = "Failed joining the session.";
                        MessageBoxScreen messageBox = new MessageBoxScreen(message);
                        messageBox.Accepted  += FailedMessageBox;
                        messageBox.Cancelled += FailedMessageBox;
                        ScreenManager.AddScreen(messageBox);

                        System.Console.WriteLine("Failed to join session:  " +
                                                 ne.Message);
                    }
                    catch (GamerPrivilegeException gpe)
                    {
                        const string message =
                            "You do not have permission to join a session.";
                        MessageBoxScreen messageBox = new MessageBoxScreen(message);
                        messageBox.Accepted  += FailedMessageBox;
                        messageBox.Cancelled += FailedMessageBox;
                        ScreenManager.AddScreen(messageBox);

                        System.Console.WriteLine(
                            "Insufficient privilege to join session:  " + gpe.Message);
                    }
                }
                else
                {
                    const string     message    = "No matches were found.";
                    MessageBoxScreen messageBox = new MessageBoxScreen(message);
                    messageBox.Accepted  += FailedMessageBox;
                    messageBox.Cancelled += FailedMessageBox;
                    ScreenManager.AddScreen(messageBox);
                }
            }
            catch (GamerPrivilegeException gpe) {
                MessageBoxScreen messageBox = new MessageBoxScreen(gpe.Message);
                messageBox.Accepted  += FailedMessageBox;
                messageBox.Cancelled += FailedMessageBox;
                ScreenManager.AddScreen(messageBox);
            }
        }
        /// <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);
            }
        }
        /// <summary>
        /// Responds to user menu selections.
        /// </summary>
        protected override void OnSelectEntry(int entryIndex)
        {
            if ((availableSessions != null) && (entryIndex >= 0) &&
                (entryIndex < availableSessions.Count))
            {
                // start to join
                try
                {
                    IAsyncResult asyncResult = NetworkSession.BeginJoin(
                        availableSessions[entryIndex], null, null);

                    // create the busy screen
                    NetworkBusyScreen busyScreen = new NetworkBusyScreen(
                        "Joining the session...", asyncResult);
                    busyScreen.OperationCompleted += LoadLobbyScreen;
                    ScreenManager.AddScreen(busyScreen);
                }
                catch (NetworkException ne)
                {
                    const string     message    = "Failed joining the session.";
                    MessageBoxScreen messageBox = new MessageBoxScreen(message);
                    messageBox.Accepted  += FailedMessageBox;
                    messageBox.Cancelled += FailedMessageBox;
                    ScreenManager.AddScreen(messageBox);

                    System.Console.WriteLine("Failed to join session:  " +
                                             ne.Message);
                }
                catch (GamerPrivilegeException gpe)
                {
                    const string message =
                        "You do not have permission to join a session.";
                    MessageBoxScreen messageBox = new MessageBoxScreen(message);
                    messageBox.Accepted  += FailedMessageBox;
                    messageBox.Cancelled += FailedMessageBox;
                    ScreenManager.AddScreen(messageBox);

                    System.Console.WriteLine(
                        "Insufficient privilege to join session:  " + gpe.Message);
                }
            }
        }
        /// <summary>
        /// Attempt to join a session using an invite that was received.
        /// </summary>
        public void JoinInvitedGame()
        {
            try
            {
                // begin to join the game we were invited to
                IAsyncResult asyncResult = NetworkSession.BeginJoinInvited(1, null, null);

                // create the busy screen
                NetworkBusyScreen busyScreen = new NetworkBusyScreen("Joining the session...", asyncResult);
                busyScreen.OperationCompleted += InvitedSessionJoined;
                ScreenManager.AddScreen(busyScreen);
            }
            catch
            {
                // could not begin to join invited game, so default to the pre-existing MainMenuScreen
            }

            ScreenManager.invited = null;
            updateState           = true;
        }
        /// <summary>
        /// Start creating a session of the given type.
        /// </summary>
        /// <param name="sessionType">The type of session to create.</param>
        void CreateSession(NetworkSessionType sessionType)
        {
            // create the session
            try
            {
                IAsyncResult asyncResult = NetworkSession.BeginCreate(sessionType, 1,
                                                                      World.MaximumPlayers, null, null);

                // create the busy screen
                NetworkBusyScreen busyScreen = new NetworkBusyScreen(
                    "Creating a session...", asyncResult);
                busyScreen.OperationCompleted += SessionCreated;
                ScreenManager.AddScreen(busyScreen);
            }
            catch (NetworkException ne)
            {
                const string     message    = "Failed creating the session.";
                MessageBoxScreen messageBox = new MessageBoxScreen(message);
                messageBox.Accepted  += FailedMessageBox;
                messageBox.Cancelled += FailedMessageBox;
                ScreenManager.AddScreen(messageBox);

                System.Console.WriteLine("Failed to create session:  " +
                                         ne.Message);
            }
            catch (GamerPrivilegeException gpe)
            {
                const string message =
                    "You do not have permission to create a session.";
                MessageBoxScreen messageBox = new MessageBoxScreen(message);
                messageBox.Accepted  += FailedMessageBox;
                messageBox.Cancelled += FailedMessageBox;
                ScreenManager.AddScreen(messageBox);

                System.Console.WriteLine(
                    "Insufficient privilege to create session:  " + gpe.Message);
            }
        }
        /// <summary>
        /// Responds to user menu selections.
        /// </summary>
        protected override void OnSelectEntry(int entryIndex)
        {
            if ((availableSessions != null) && (entryIndex >= 0) && 
                (entryIndex < availableSessions.Count))
            {
                // start to join
                try
                {
                    IAsyncResult asyncResult = NetworkSession.BeginJoin(
                        availableSessions[entryIndex], null, null);

                    // create the busy screen
                    NetworkBusyScreen busyScreen = new NetworkBusyScreen(
                        "Joining the session...", asyncResult);
                    busyScreen.OperationCompleted += LoadLobbyScreen;
                    ScreenManager.AddScreen(busyScreen);
                }
                catch (NetworkException ne)
                {
                    const string message = "Failed joining the session.";
                    MessageBoxScreen messageBox = new MessageBoxScreen(message);
                    messageBox.Accepted += FailedMessageBox;
                    messageBox.Cancelled += FailedMessageBox;
                    ScreenManager.AddScreen(messageBox);

                    System.Console.WriteLine("Failed to join session:  " +
                        ne.Message);
                }
                catch (GamerPrivilegeException gpe)
                {
                    const string message =
                        "You do not have permission to join a session.";
                    MessageBoxScreen messageBox = new MessageBoxScreen(message);
                    messageBox.Accepted += FailedMessageBox;
                    messageBox.Cancelled += FailedMessageBox;
                    ScreenManager.AddScreen(messageBox);

                    System.Console.WriteLine(
                        "Insufficient privilege to join session:  " + gpe.Message);
                }
            }
        }
        /// <summary>
        /// Callback to receive the network-session search results from quick-match.
        /// </summary>
        void QuickMatchSearchCompleted(object sender, OperationCompletedEventArgs e)
        {
            try
            {
                AvailableNetworkSessionCollection availableSessions =
                    NetworkSession.EndFind(e.AsyncResult);
                if ((availableSessions != null) && (availableSessions.Count > 0))
                {
                    // join the session
                    try
                    {
                        IAsyncResult asyncResult = NetworkSession.BeginJoin(
                            availableSessions[0], null, null);

                        // create the busy screen
                        NetworkBusyScreen busyScreen = new NetworkBusyScreen(
                            "Joining the session...", asyncResult);
                        busyScreen.OperationCompleted += QuickMatchSessionJoined;
                        ScreenManager.AddScreen(busyScreen);
                    }
                    catch (NetworkException ne)
                    {
                        const string message = "Failed joining the session.";
                        MessageBoxScreen messageBox = new MessageBoxScreen(message);
                        messageBox.Accepted += FailedMessageBox;
                        messageBox.Cancelled += FailedMessageBox;
                        ScreenManager.AddScreen(messageBox);

                        System.Console.WriteLine("Failed to join session:  " +
                            ne.Message);
                    }
                    catch (GamerPrivilegeException gpe)
                    {
                        const string message =
                            "You do not have permission to join a session.";
                        MessageBoxScreen messageBox = new MessageBoxScreen(message);
                        messageBox.Accepted += FailedMessageBox;
                        messageBox.Cancelled += FailedMessageBox;
                        ScreenManager.AddScreen(messageBox);

                        System.Console.WriteLine(
                            "Insufficient privilege to join session:  " + gpe.Message);
                    }
                }
                else
                {
                    const string message = "No matches were found.";
                    MessageBoxScreen messageBox = new MessageBoxScreen(message);
                    messageBox.Accepted += FailedMessageBox;
                    messageBox.Cancelled += FailedMessageBox;
                    ScreenManager.AddScreen(messageBox);
                }
            }
            catch (GamerPrivilegeException gpe){
                MessageBoxScreen messageBox = new MessageBoxScreen(gpe.Message);
                messageBox.Accepted += FailedMessageBox;
                messageBox.Cancelled += FailedMessageBox;
                ScreenManager.AddScreen(messageBox);
            }
        }
        /// <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);
            }
        }
        /// <summary>
        /// Start creating a session of the given type.
        /// </summary>
        /// <param name="sessionType">The type of session to create.</param>
        void CreateSession(NetworkSessionType sessionType)
        {
            // create the session
            try
            {
                IAsyncResult asyncResult = NetworkSession.BeginCreate(sessionType, 1,
                    World.MaximumPlayers, null, null);

                // create the busy screen
                NetworkBusyScreen busyScreen = new NetworkBusyScreen(
                    "Creating a session...", asyncResult);
                busyScreen.OperationCompleted += SessionCreated;
                ScreenManager.AddScreen(busyScreen);
            }
            catch (NetworkException ne)
            {
                const string message = "Failed creating the session.";
                MessageBoxScreen messageBox = new MessageBoxScreen(message);
                messageBox.Accepted += FailedMessageBox;
                messageBox.Cancelled += FailedMessageBox;
                ScreenManager.AddScreen(messageBox);

                System.Console.WriteLine("Failed to create session:  " +
                    ne.Message);
            }
            catch (GamerPrivilegeException gpe)
            {
                const string message =
                    "You do not have permission to create a session.";
                MessageBoxScreen messageBox = new MessageBoxScreen(message);
                messageBox.Accepted += FailedMessageBox;
                messageBox.Cancelled += FailedMessageBox;
                ScreenManager.AddScreen(messageBox);

                System.Console.WriteLine(
                    "Insufficient privilege to create session:  " + gpe.Message);
            }
        }
        /// <summary>
        /// Attempt to join a session using an invite that was received.
        /// </summary>
        public void JoinInvitedGame()
        {
            try
            {
                // begin to join the game we were invited to
                IAsyncResult asyncResult = NetworkSession.BeginJoinInvited(1, null, null);

                // create the busy screen
                NetworkBusyScreen busyScreen = new NetworkBusyScreen("Joining the session...", asyncResult);
                busyScreen.OperationCompleted += InvitedSessionJoined;
                ScreenManager.AddScreen(busyScreen);
            }
            catch
            {
                // could not begin to join invited game, so default to the pre-existing MainMenuScreen
            }

            ScreenManager.invited = null;
            updateState = true;
        }