private void doWork() { int dataCount = Int32.Parse(AddDevNumtextBox.Text);//数据生成数量 //设置进度条 this.Invoke((EventHandler) delegate { this.AddDevprogressBar.Minimum = 0; }); this.Invoke((EventHandler) delegate { this.AddDevprogressBar.Step = 1; }); this.Invoke((EventHandler) delegate { this.AddDevprogressBar.Maximum = dataCount; }); //AddDevprogressBar.Maximum = dataCount; string name = "视频主机"; //资产名称的前缀 string deviceCode = StringUtil.getDateTimeNum(); //资产编码和设备唯一标识码的前缀 string[] sArray = AddIpAddresstextBox.Text.Split('.'); int Port = Int32.Parse(AddPorttextBox.Text); int IPCount = Int32.Parse(sArray[3]); //ip尾号 int channelCount = Int32.Parse(AddChanneltextBox.Text); //通道数量 for (int i = 0; i < dataCount;) { int left = dataCount - i; //控制一次insert新增的数据量 int count = left > AddDeviceHelper.ONCE_INSERT ? AddDeviceHelper.ONCE_INSERT : left; List <Device> devices = new List <Device>(); for (int j = 0; j < count; j++, i++) { VideoDevice video = new VideoDevice(); video.setIp(string.Format("{0}.{1}.{2}.{3}", sArray[0], sArray[1], sArray[2], IPCount++)); video.setPort(Port.ToString()); video.setDeviceCode(deviceCode + i.ToString()); video.setDeviceName(name + i.ToString()); video.setChannelCount(channelCount); devices.Add(video); this.Invoke((EventHandler) delegate { this.AddDevprogressBar.Value += AddDevprogressBar.Step; }); //AddDevprogressBar.Value += AddDevprogressBar.Step;//让进度条增加一次 } AddDeviceHelper.multiExcute(LoginMysqlFm.getNewDbHelper(), devices);//执行数据新增操作 } MessageBox.Show("添加成功"); }