public void StartSender()
 {
     _senderThread = new SenderThread();
       _senderThread.Start();
 }
        public void NetworkAvailability(bool IsAvailable)
        {
            try
            {
                _networkIsAvailable = IsAvailable;

                if (_networkIsAvailable)
                {
                    LogFile.Network("Network Available.");
                    StartListener();
                }
                else
                {
                    LogFile.Network("Network Unavailable.");

                    if (_senderThread != null)
                    {
                        _senderThread.Stop();
                        _senderThread = null;
                    }

                    if (_listenerThread != null)
                    {
                        _listenerThread.Stop();
                        _listenerThread = null;
                    }
                }
            }
            catch (SocketException se)
            {
                LogFile.Network(se.ToString());
            }
            catch (Exception ex)
            {
                LogFile.Network(ex.ToString());
            }
        }