/// <summary>
        /// Thread function that actually run the socket work.
        /// </summary>
        private void MainThread()
        {
            while (_active)
            {
                byte[] arr = null;

                try
                {
                    int length = Convert.ToInt32(tr.ReadInt32());
                    arr = new byte[length];
                    int index = 0;

                    while (length > 0)
                    {
                        int receivedBytes = tr.Read(arr, index, length);
                        length -= receivedBytes;
                        index  += receivedBytes;
                    }
                }
                catch (Exception ex)
                {
                    Debug.WriteLine(ex.ToString());
                }

                lock (_lock)
                {
                    if (_active)
                    {
                        Boolean Stato = _client.Client.Poll(100, SelectMode.SelectRead);
                        if ((arr == null) && (Stato == true))
                        {
                            break;
                        }
                        else
                        {
                            _server.RaiseDataReceivedEvent(this, new Data(arr));
                        }
                    }
                    else
                    {
                        break;
                    }
                }
            }
            Stop();
        }