Example #1
0
        private void worker_DoWork(object sender, DoWorkEventArgs e)
        {
            int endNum = 0;

            if (e.Argument != null)
            {
                endNum = int.Parse(e.Argument.ToString());
                for (int i = endNum; i > 0; i--)
                {
                    if (!worker.CancellationPending)
                    {
                        Thread.Sleep(1000);
                        worker.ReportProgress(i - 1);
                    }
                    else
                    {
                        e.Cancel = true;
                        return;
                    }
                }
                if (!SocketClientHelper.ConnectionServer())
                {
                    worker.RunWorkerAsync(60);
                }
            }
        }
Example #2
0
 private void linklblConnention_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
 {
     if (SocketClientHelper.ConnectionServer())
     {
         FormHelper.IsConnect();
         worker.CancelAsync();
     }
     else
     {
         txtReciveMsg.Text += $"重连失败{Environment.NewLine}";
     }
 }
Example #3
0
 private void worker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
 {
     //判断任务完成是正常完成还是被取消掉
     if (!e.Cancelled)
     {
         if (SocketClientHelper.ConnectionServer())
         {
             FormHelper.IsConnect();
         }
         else
         {
             txtReciveMsg.Text += $"重连失败{Environment.NewLine}";
             worker.RunWorkerAsync(60);
         }
     }
 }
Example #4
0
 private void FrmShowMsg_Load(object sender, EventArgs e)
 {
     try
     {
         //将窗体当作变量赋值给类,以便于在类中操作窗体中的控件
         FormHelper.frm = this;
         cmbAction.Items.Add(new { DisplayMember = "请选择消息类型", ValueMember = "" });
         cmbAction.Items.Add(new { DisplayMember = "心跳", ValueMember = "HEARTBEAT" });
         cmbAction.Items.Add(new { DisplayMember = "登陆", ValueMember = "LOGIN" });
         cmbAction.SelectedIndex = 0;
         cmbAction.DisplayMember = "DisplayMember";
         cmbAction.ValueMember   = "ValueMember";
         if (SocketClientHelper.ConnectionServer())
         {
             //绑定信息接收事件
             SocketClientHelper.socketClient.NewPackageReceived += SocketClient_NewPackageReceived;
             SocketClientHelper.socketClient.Closed             += SocketClient_Closed;
             SocketClientHelper.socketClient.Connected          += SocketClient_Connected;
             FormHelper.IsConnect();
             dynamic body     = new { SN = DateTime.Now.ToString() };
             string  bodyStr  = JsonConvert.SerializeObject(body);
             var     bodyByte = Encoding.UTF8.GetBytes(bodyStr);
             var     rsLogin  = new List <byte> {
                 0, 1
             };
             rsLogin.AddRange(BitConverter.GetBytes((ushort)(bodyByte.Length)).Reverse().ToArray());
             rsLogin.AddRange(bodyByte);
             SocketClientHelper.socketClient.Send(rsLogin.ToArray());
             QuartzHelper.Start();
         }
         else
         {
             FormHelper.DisConnect();
             worker.RunWorkerAsync(60);
         }
     }
     catch (Exception ex)
     {
         throw;
     }
 }