}\r
}\r
\r
+ // TODO: New method.\r
+ void AsyncCallbackFailed(Exception exception, NetworkGame networkGame)\r
+ {\r
+ currentState = lobbyState.Welcome;\r
+ Console.WriteLine("Exception as thrown during async call: " + exception.Message);\r
+ }\r
+\r
+\r
public long Update(GameTime gameTime, NetworkGame networkGame)\r
{\r
\r
if (currentKeyboardState.IsKeyDown(Keys.Y) && previousKeyboardState.IsKeyUp(Keys.Y))\r
{\r
currentState = lobbyState.JoiningGame;\r
+ networkGame.ErrorDelegate = AsyncCallbackFailed;\r
networkGame.CreateSession(JoinedSession);\r
} \r
break;\r
currentState = lobbyState.Welcome;\r
ready = false;\r
}\r
+ networkGame.ErrorDelegate = AsyncCallbackFailed;\r
networkGame.FindSessions(FoundSessions);\r
currentState = lobbyState.FindingGames;\r
break;\r
public delegate void FoundSessionsDelegate(AvailableNetworkSessionCollection sessions, NetworkGame networkGame);\r
\r
\r
+ /// <summary>\r
+ /// Called when an exception is thrown during an asynchronous operation.\r
+ /// </summary>\r
+ /// <param name="exception">The exception that was thrown.</param>\r
+ /// <param name="networkGame">The NetworkGame that errored.</param>\r
+ public delegate void CaughtErrorDelegate(Exception exception, NetworkGame networkGame);\r
+\r
+ /// <summary>\r
+ /// Get and set the error delegate, called when an exception is thrown during\r
+ /// and asynchronous operation. This will occur if you try to create or join a\r
+ /// session without being logged into a profile.\r
+ /// </summary>\r
+ public CaughtErrorDelegate ErrorDelegate;\r
+\r
+\r
/// <summary>\r
/// Construct a NetworkGame with a lobby and a game.\r
/// </summary>\r
{\r
Debug.Assert(mNetworkSession == null);\r
\r
- mNetworkSession = NetworkSession.EndCreate(result);\r
- mNetworkSession.AllowHostMigration = true;\r
- mNetworkSession.AllowJoinInProgress = false;\r
- mNetworkSession.GameStarted += new EventHandler<GameStartedEventArgs>(mNetworkSession_GameStarted);\r
+ try\r
+ {\r
+ mNetworkSession = NetworkSession.EndCreate(result);\r
+ mNetworkSession.AllowHostMigration = true;\r
+ mNetworkSession.AllowJoinInProgress = false;\r
+ mNetworkSession.GameStarted += new EventHandler<GameStartedEventArgs>(mNetworkSession_GameStarted);\r
+ }\r
+ catch (Exception e)\r
+ {\r
+ if (ErrorDelegate != null) ErrorDelegate(e, this);\r
+ return;\r
+ }\r
mJoinedSessionDelegate(mNetworkSession, this);\r
+ mJoinedSessionDelegate = null;\r
}\r
\r
\r
}\r
private void FindSessionsEnd(IAsyncResult result)\r
{\r
- AvailableNetworkSessionCollection sessions = NetworkSession.EndFind(result);\r
+ AvailableNetworkSessionCollection sessions;\r
+ try\r
+ {\r
+ sessions = NetworkSession.EndFind(result);\r
+ }\r
+ catch (Exception e)\r
+ {\r
+ if (ErrorDelegate != null) ErrorDelegate(e, this);\r
+ return;\r
+ }\r
mFoundSessionsDelegate(sessions, this);\r
+ mFoundSessionsDelegate = null;\r
}\r
\r
/// <summary>\r
{\r
Debug.Assert(mNetworkSession == null);\r
\r
- mNetworkSession = NetworkSession.EndJoin(result);\r
-\r
+ try\r
+ {\r
+ mNetworkSession = NetworkSession.EndJoin(result);\r
+ mNetworkSession.GameStarted += new EventHandler<GameStartedEventArgs>(mNetworkSession_GameStarted);\r
+ }\r
+ catch (Exception e)\r
+ {\r
+ if (ErrorDelegate != null) ErrorDelegate(e, this);\r
+ return;\r
+ }\r
mJoinedSessionDelegate(mNetworkSession, this);\r
mJoinedSessionDelegate = null;\r
-\r
- mNetworkSession.GameStarted += new EventHandler<GameStartedEventArgs>(mNetworkSession_GameStarted);\r
}\r
\r
\r