NewTOAPIA.Net.Rtp.RtpSession.DisposeNetwork C# (CSharp) Method

DisposeNetwork() private method

Dispose the Rtcp/Rtp listeners and senders Usually one would dispose items in the opposite order from which they were created in order to maintain symmetry. However, because objects are created due to data received from the network, we first shut down the Rtcp/Rtp listeners so as not to create new objects during shutdown. Since we are no longer listening on the network, we won't receive our own "dispose" messages that we send out, so we dispose the items manually using the same methods as if the data had come in off the wire. This allows for proper eventing and logging.
private DisposeNetwork ( ) : void
return void
        private void DisposeNetwork()
        {
            if(receiveData)
            {
                // Prevent new streams from being created
                rtcpListener.Dispose();
            }

            if(participant != null)
            {
                if(rtpTraffic)
                {
                    DisposeRtpSenders();
                    DisposeRtpStreams();

                    if(receiveData)
                    {
                        rtpListener.Dispose();
                    }
                }

                AddBye(participant.SSRC);
                RemoveParticipant(participant);

                // Send last Rtcp packet (which will contain BYEs)
                rtcpSender.SendRtcpDataNow();
                rtcpSender.Dispose();
            }
        }