OpenMetaverse.UDPBase.Stop C# (CSharp) Method

Stop() public method

public Stop ( ) : void
return void
        public void Stop()
        {
            if (!shutdownFlag)
            {
                // wait indefinitely for a writer lock.  Once this is called, the .NET runtime
                // will deny any more reader locks, in effect blocking all other send/receive
                // threads.  Once we have the lock, we set shutdownFlag to inform the other
                // threads that the socket is closed.
                rwLock.AcquireWriterLock(-1);
                shutdownFlag = true;
                udpSocket.Close();
                rwLock.ReleaseWriterLock();

                // wait for any pending operations to complete on other
                // threads before exiting.
                const int FORCE_STOP = 100;
                int i = 0;
                while (rwOperationCount > 0 && i < FORCE_STOP)
                {
                    Thread.Sleep(10);
                    ++i;
                }

                if (i >= FORCE_STOP)
                {
                    Logger.Log("UDPBase.Stop() forced shutdown while waiting on pending operations",
                        Helpers.LogLevel.Warning);
                }
            }
        }