Beispiel #1
0
 public static NetworkSession EndCreate(IAsyncResult result)
 {
     Session = null;
     try
     {
         Session = AsyncCreateCaller.EndInvoke(result);
     }
     catch
     {
         throw;
     }
     finally
     {
         AsyncCreateCaller = null;
     }
     return(Session);
 }
Beispiel #2
0
        // Asynchronous session creation
        public static IAsyncResult BeginCreate(NetworkSessionType sessionType, IEnumerable <SignedInGamer> localGamers, int maxGamers, int privateGamerSlots, NetworkSessionProperties sessionProperties, AsyncCallback callback, Object asyncState)
        {
            if (Session != null || AsyncCreateCaller != null || AsyncFindCaller != null || AsyncJoinCaller != null)
            {
                throw new InvalidOperationException("Only one NetworkSession allowed");
            }
            if (localGamers == null)
            {
                throw new ArgumentNullException("localGamers");
            }
            foreach (var localGamer in localGamers)
            {
                if (localGamer == null)
                {
                    throw new ArgumentNullException("Element of localGamers");
                }
            }
            if (maxGamers < MinSupportedGamers || maxGamers > MaxSupportedGamers)
            {
                throw new ArgumentOutOfRangeException("maxGamers must be in the range [" + MinSupportedGamers + ", " + MaxSupportedGamers + "]");
            }
            if (privateGamerSlots < 0 || privateGamerSlots > maxGamers)
            {
                throw new ArgumentOutOfRangeException("privateGamerSlots must be in the range [0, maxGamers]");
            }
            if (sessionProperties == null)
            {
                sessionProperties = new NetworkSessionProperties();
            }

            AsyncCreateCaller = new AsyncCreate(InternalCreate);
            IAsyncResult result = null;

            try
            {
                result = AsyncCreateCaller.BeginInvoke(sessionType, localGamers, maxGamers, privateGamerSlots, sessionProperties, callback, asyncState);
            }
            catch
            {
                AsyncCreateCaller = null;
                throw;
            }
            return(result);
        }