Ejemplo n.º 1
0
        //---------------------------------------------------------------------
        #endregion // Constructors

        #region DirectPlay Object Initializations
        //---------------------------------------------------------------------

        /// <summary>
        /// Initializes the DirectPlay Peer object
        /// </summary>
        private void InitDirectPlay()
        {
            // Release any exising resources
            if (myPeer != null)
            {
                myPeer.CancelAsyncOperation(CancelFlags.AllOperations);
                myPeer.Dispose();
            }

            if (myThreadPool != null)
            {
                myThreadPool.Dispose();
            }

            // Create the ThreadPool
            myThreadPool = new DirectPlay.ThreadPool();

            // Create a new DirectPlay Peer object
            myPeer = new Peer();

            // Add handlers for DirectPlay events
            myPeer.FindHostResponse  += new FindHostResponseEventHandler(FindHostResponseHandler);
            myPeer.Receive           += new ReceiveEventHandler(ReceiveHandler);
            myPeer.HostMigrated      += new HostMigratedEventHandler(HostMigratedHandler);
            myPeer.SessionTerminated += new SessionTerminatedEventHandler(SessionTerminatedHandler);

            // Turn off worker DirectPlay worker threads since we'll be using the DoWork
            // method to synchronously handle network messages.
            myThreadPool.SetThreadCount(-1, 0);

            myConnection = ConnectionType.Disconnected;
        }
Ejemplo n.º 2
0
    /// <summary>
    /// Clean up any resources being used.
    /// </summary>
    protected override void Dispose(bool Disposing)
    {
        base.Dispose(Disposing);

        if (isSearching)
        {
            if (findHostHandle != 0)
            {
                peer.CancelAsyncOperation(findHostHandle);
            }
            isSearching = !isSearching;
        }
        if (connectTimer != null)
        {
            connectTimer.Dispose();
        }

        if (updateListTimer != null)
        {
            updateListTimer.Dispose();
        }
    }