private void btnStart_Click(object sender, EventArgs e) { this.TargetClientCount = this.txtClientCount.Text.Trim().ToInt(); btnClose_Click(null, null); this.btnCreateDevice.Enabled = false; this.btnStart.Enabled = false; this.txtServerAddress.Enabled = false; this.txtServerPort.Enabled = false; this.txtClientCount.Enabled = false; this.txtCurrencyCount.Enabled = false; this.txtDay.Enabled = false; this.txtTimeOut.Enabled = false; this.cbFixedSendSpeed.Enabled = false; this.ClientList = new List <CurrencyTerminal>(); Task.Factory.StartNew(() => { for (int i = 0; i < this.txtClientCount.Text.Trim().ToInt(); i++) { CurrencyTerminal client = new CurrencyTerminal(this.txtServerAddress.Text.Trim(), this.txtServerPort.Text.Trim().ToInt()); client.DeviceNumber = this.DeviceNumberList.ElementAtOrDefault(i); client.DeviceNumberHex = client.DeviceNumber.GetDeviceNumberHex(); client.TargetReconnectCount = this.txtReconnectCount.Text.Trim().ToInt(); client.TargetCurrencyCount = this.txtCurrencyCount.Text.Trim().ToInt() * this.txtDay.Text.Trim().ToInt(); client.TargetDayCount = this.txtDay.Text.Trim().ToInt(); client.TargetSingleDayCurrencyCount = this.txtCurrencyCount.Text.Trim().ToInt(); client.TimeOut = this.txtTimeOut.Text.Trim().ToInt(); client.FixedSendSpeed = this.cbFixedSendSpeed.Checked; client.Reset(); client.Connect(); this.ClientList.Add(client); this.BeginInvoke(new EventHandler((a, b) => { this.lblRealClientCount.Text = this.ClientList.Count.ToString(); })); Thread.Sleep(5); } this.BeginInvoke(new EventHandler((a, b) => { this.btnClose.Enabled = true; this.rbHeartbeat.Enabled = true; this.rbLogin.Enabled = true; this.rbBlacklist.Enabled = true; this.rbCurrency.Enabled = true; this.btnSendData.Enabled = true; })); }); }
private void btnStart_Click(object sender, EventArgs e) { this.TargetClientCount = this.txtClientCount.Text.Trim().ToInt(); btnClose_Click(null, null); this.btnCreateDevice.Enabled = false; this.btnStart.Enabled = false; this.txtServerAddress.Enabled = false; this.txtServerPort.Enabled = false; this.txtClientCount.Enabled = false; this.txtCurrencyCount.Enabled = false; this.txtDay.Enabled = false; this.txtTimeOut.Enabled = false; this.cbFixedSendSpeed.Enabled = false; this.ClientList = new List<CurrencyTerminal>(); Task.Factory.StartNew(() => { for (int i = 0; i < this.txtClientCount.Text.Trim().ToInt(); i++) { CurrencyTerminal client = new CurrencyTerminal(this.txtServerAddress.Text.Trim(), this.txtServerPort.Text.Trim().ToInt()); client.DeviceNumber = this.DeviceNumberList.ElementAtOrDefault(i); client.DeviceNumberHex = client.DeviceNumber.GetDeviceNumberHex(); client.TargetReconnectCount = this.txtReconnectCount.Text.Trim().ToInt(); client.TargetCurrencyCount = this.txtCurrencyCount.Text.Trim().ToInt() * this.txtDay.Text.Trim().ToInt(); client.TargetDayCount = this.txtDay.Text.Trim().ToInt(); client.TargetSingleDayCurrencyCount = this.txtCurrencyCount.Text.Trim().ToInt(); client.TimeOut = this.txtTimeOut.Text.Trim().ToInt(); client.FixedSendSpeed = this.cbFixedSendSpeed.Checked; client.Reset(); client.Connect(); this.ClientList.Add(client); this.BeginInvoke(new EventHandler((a, b) => { this.lblRealClientCount.Text = this.ClientList.Count.ToString(); })); Thread.Sleep(5); } this.BeginInvoke(new EventHandler((a, b) => { this.btnClose.Enabled = true; this.rbHeartbeat.Enabled = true; this.rbLogin.Enabled = true; this.rbBlacklist.Enabled = true; this.rbCurrency.Enabled = true; this.btnSendData.Enabled = true; })); }); }
private void btnRefresh_Click(object sender, EventArgs e) { float R = 7.0f; this.lvClientList.Items.Clear(); DataCounter.ClearConnectedClient(); if (this.ClientList != null && this.ClientList.Count > 0) { Task.Factory.StartNew(() => { int maxX = this.panelStatus.Width; int maxY = this.panelStatus.Height; int maxXCout = (int)(maxX / R); int maxYCout = (int)(maxY / R); if (maxXCout == 0) { return; } this.BeginInvoke(new EventHandler((ob, ca) => { for (int p = 0; p < this.ClientList.Count; p++) { CurrencyTerminal client = this.ClientList[p]; XListViewItem lviClient = new XListViewItem(client.DeviceNumber, client.RealConnectCount, "", client.TimeOutCount, client.SendHeartbeatCount, client.SendLoginCount, client.DownloadBlacklistCount, client.SendCurrencyCount, client.ConnectMessage); float drawX = p % maxXCout * R; float drawY = p / maxXCout * R; if (client != null) { using (Graphics g = Graphics.FromHwnd(this.panelStatus.Handle)) { if (client.IsConnected && client.IsRecieveNormal) { lviClient.DeviceStatus = "工作中"; lviClient.ForeColor = Color.Green; g.FillEllipse(Brushes.Green, drawX, drawY, R, R); DataCounter.AddConnectedClient(); } else if (client.IsConnected) { lviClient.DeviceStatus = "已连接"; lviClient.ForeColor = Color.Blue; g.FillEllipse(Brushes.Blue, drawX, drawY, R, R); DataCounter.AddConnectedClient(); } else if (!client.IsConnected) { lviClient.DeviceStatus = "未连接"; lviClient.ForeColor = Color.Red; g.FillEllipse(Brushes.Red, drawX, drawY, R, R); } else { lviClient.DeviceStatus = "未知"; lviClient.ForeColor = Color.Black; g.FillEllipse(Brushes.Black, drawX, drawY, R, R); } g.Save(); this.lvClientList.Items.Add(lviClient); } } } })); }); } }