コード例 #1
0
ファイル: PageMain.xaml.cs プロジェクト: sttrox/ChatLAN
        private void BtnJoinOnClick(object sender, RoutedEventArgs e)
        {
            PanelOfClient.Visibility = Visibility.Collapsed;
            ProgressRing.Visibility  = Visibility.Visible;

            if (!ValidationAdress(TbAdress.Text))
            {
                PrintAndReturnButton("Ошибка", "Неверный IP адрес");
                return;
            }

            byte[]     ipAdress = getIpAdress(TbAdress.Text);
            int        port     = int.Parse(NumPort.Value.ToString());
            string     login    = TbLogin.Text;
            ClientCore client;

            new Thread(() =>
            {
                client = ClientCore.InicializeClient(ipAdress, port);
                if (client == null)
                {
                    ClientCore.RemoveClient();
                    MessageOnError(null, "Что-то пошло не так, попробуйте снова");
                    return;
                }

                client.Error -= MessageOnError;
                client.Error += MessageOnError;
                client.Join  -= OpenPageServer;
                client.Join  += OpenPageServer;
                client.JoinServer(login);
            }).Start();
        }