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); } } } })); }); } }
static DataCounter() { DataCounter.ClearConnectedClient(); DataCounter.Reset(); }