示例#1
0
        public static ConnectWindow ShowAndConnect(IPAddress address, ushort port, bool preferUdp)
        {
            ConnectWindow wnd = new ConnectWindow();

            wnd.Address   = address;
            wnd.Port      = port;
            wnd.PreferUdp = preferUdp;

            wnd.Show();
            wnd.Start();

            return(wnd);
        }
示例#2
0
        public void Start()
        {
            IPAddress add = Address;
            ushort    prt = Port;
            bool      udp = PreferUdp;

            ConnectionTask = new Task(() =>
            {
                ConnectWindow parent = this;
                Client c             = new Client(add, prt, udp);
                c.Start();

                if (parent.Aborted)
                {
                    c.Stop();
                    return;
                }

                Settings.Volatile.ActiveServer.AttachClient(c);
            });
            ConnectionTask.ContinueWith(task =>
            {
                Dispatcher.Invoke(() =>
                {
                    if (Aborted)
                    {
                        return;
                    }

                    if (task.IsFaulted)
                    {
                        MessageBox.Show(
                            "An error occured while trying to connect to the specified address.\n\n" +
                            Address.ToString() +
                            " : " + (PreferUdp
                                ? "UDP "
                                : "TCP ") + Port + "\n\n" + task.Exception?.ToString(), "Connection error",
                            MessageBoxButton.OK, MessageBoxImage.Error);
                    }

                    this.Close();
                });
            });
            ConnectionTask.Start();
        }