public void StartListener()
 {
     _listenerThread = new ListenerThread();
       _listenerThread.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());
            }
        }