private void ConnectionLoopStart()
        {
            try
            {
                ConnectionActive = true;
                while (ConnectionActive)
                {
                    var receivedString = Socket.ReceiveAll(Encoding);

                    ActionsProcessor.AddActionToQueue(() =>
                    {
                        Debug.Log(receivedString);
                        CommandInterface.GetExecutor(receivedString, new NetArgs(Socket))();
                    });
                }

                Socket.Shutdown(SocketShutdown.Both);
                Socket.Close();
                ConnectionActive = false;
            }
            catch (SocketException)
            {
                Debug.LogError("Disconnect!");
                LoginConnect();
            }
            catch (ThreadAbortException)
            {
                ConnectionThread = null;
                Dispose();
            }
        }
        private void Connection()
        {
            ActionsProcessor.AddActionToQueue(() =>
                                              Ui.ResourcesLineConnectionStatus.Content = UiController.ConnectionStatusConnection);

            var ipPoint = new IPEndPoint(IPAddress.Parse(ServerAddress), ServerPort);

            Socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);

            var connected        = false;
            var connectBeginTime = DateTime.Now;

            do
            {
                try
                {
                    Socket.Connect(ipPoint);
                    connected = true;
                    break;
                }
                catch (SocketException)
                {
                    Thread.Sleep(ConnectDelayMilliseconds);
                }
            } while ((DateTime.Now - connectBeginTime).Seconds < ConnectTimeSeconds);

            if (!connected)
            {
                ActionsProcessor.AddActionToQueue(() =>
                {
                    if (OnConnectionFail != null)
                    {
                        OnConnectionFail();
                    }
                });

                throw new SocketException();
            }

            ActionsProcessor.AddActionToQueue(() =>
            {
                if (OnConnectionSuccess != null)
                {
                    OnConnectionSuccess();
                }
            });

            ActionsProcessor.AddActionToQueue(() =>
                                              Ui.ResourcesLineConnectionStatus.Content = UiController.ConnectionStatusConnected);
        }