Beispiel #1
0
        /// <summary>
        /// 网络连接信息
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void LinkMsg_TestArrived(object sender, NetDataArrivedEventArgs e)
        {
            Action <string> myDelegate = UpdateLinkTxt;

            Dispatcher.BeginInvoke(myDelegate, e.DataMsg);

            isTcpRun = true; //连接成功标识
            //作为客户端需要启动接收
            if (linkMode == LinkNetMode.TcpClient)
            {
                ClientReciveConfig();
            }
        }
Beispiel #2
0
        /// <summary>
        /// TCP连接出现异常
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Exception_TestArrived(object sender, NetDataArrivedEventArgs e)
        {
            Action <string> myDelegate = UpdateLinkTxt;

            Dispatcher.BeginInvoke(myDelegate, e.DataMsg);

            Action bk = () =>
            {
                btnStopServer_Click(null, null);
                if (true == checkIsReStart.IsChecked)
                {
                    txtLinkMsg.Text += "服务器端将在" + reLinkMs.ToString() + "ms后重新连接;\n";
                    txtLinkMsg.ScrollToEnd();
                }
            };

            Dispatcher.BeginInvoke(bk);
            Thread.Sleep(reLinkMs);
            Action <int> restart = ReStartServer;

            Dispatcher.BeginInvoke(restart, reLinkMs);
        }