コード例 #1
0
        /// <inheritdoc />
        public bool Run()
        {
            if (InternalStorage.RunningClient != null)
            {
                throw new Exception("A game mode is already running!");
            }

            InternalStorage.RunningClient = this;

            // Prepare the synchronization context
            var queue = new SemaphoreMessageQueue();

            _synchronizationContext = new SampSharpSynchronizationContext(queue);
            _messagePump            = new MessagePump(queue);

            SynchronizationContext.SetSynchronizationContext(_synchronizationContext);

            // Initialize the game mode and start the main routine
            Initialize();

            // Pump new tasks
            _messagePump.Pump(e => OnUnhandledException(new UnhandledExceptionEventArgs("async", e)));

            // Clean up
            InternalStorage.RunningClient = null;
            CommunicationClient.Disconnect();

            return(_shuttingDown);
        }
コード例 #2
0
        /// <summary>
        ///     Runs this game mode client.
        /// </summary>
        /// <returns>true if shut down by the game mode, false otherwise.</returns>
        /// <exception cref="Exception">Thrown if a game mode is already running.</exception>
        public bool Run()
        {
            if (InternalStorage.RunningClient != null)
            {
                throw new Exception("A game mode is already running!");
            }

            InternalStorage.RunningClient = this;

            // Prepare the syncronization context
            _syncronizationContext = new SampSharpSyncronizationContext();
            _messagePump           = _syncronizationContext.MessagePump;

            SynchronizationContext.SetSynchronizationContext(_syncronizationContext);

            // Initialize the game mode and start the main routine
            Initialize();

            // Pump new tasks
            _messagePump.Pump();

            // Clean up
            InternalStorage.RunningClient = null;
            CommunicationClient.Disconnect();

            return(_shuttingDown);
        }