private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e) { int[] speeds = { speed1, speed2, speed3 }; System.ComponentModel.BackgroundWorker worker; worker = (System.ComponentModel.BackgroundWorker)sender; networkProtocol np = (networkProtocol)e.Argument; np.workState = working; np.serialPingServers(worker, e, speeds); }
private void backgroundWorker2_DoWork(object sender, DoWorkEventArgs e) { // Параллельный поток для отдельного хоста (ускорение прохода по списку хостов). int[] speeds = { speed1, speed2, speed3 }; System.ComponentModel.BackgroundWorker worker; worker = (System.ComponentModel.BackgroundWorker)sender; var myArgs = e.Argument as MyWorkerArgs; serverControl serv = myArgs.srv; networkProtocol np = myArgs.netP; workState = working; np.workState = working; np.parallelPingServers(worker, e, speeds, serv); }
public string picON, picOFF; // путь к картинкам private void connectToolStripMenuItem_Click(object sender, EventArgs e) { networkProtocol np = new networkProtocol(); np.serverList = servers; if (!backgroundWorker1.IsBusy) { backgroundWorker1.RunWorkerAsync(np); toolStripProgressBar1.Visible = true; toolStripStatusLabel2.Text = "Waiting for ping"; toolStripStatusLabel2.Visible = true; } }
private void serialPinging() { cancel = false; networkProtocol np = new networkProtocol(); np.serverList = servers; if (!backgroundWorker1.IsBusy) { backgroundWorker1.RunWorkerAsync(np); toolStripProgressBar1.Visible = true; toolStripStatusLabel2.Text = "Waiting for serial ping"; toolStripStatusLabel2.Visible = true; } }
private void parallelPinging() { cancel = false; networkProtocol np = new networkProtocol(); np.serverList = servers; foreach (serverControl server in servers) { threadList.Add(new BackgroundWorker() { WorkerReportsProgress = true, WorkerSupportsCancellation = true }); threadList.Last().DoWork += new System.ComponentModel.DoWorkEventHandler(this.backgroundWorker2_DoWork); threadList.Last().ProgressChanged += new System.ComponentModel.ProgressChangedEventHandler(this.backgroundWorker2_ProgressChanged); threadList.Last().RunWorkerCompleted += new System.ComponentModel.RunWorkerCompletedEventHandler(this.backgroundWorker2_RunWorkerCompleted); threadList.Last().RunWorkerAsync(new MyWorkerArgs(server, np)); toolStripProgressBar1.Visible = true; toolStripStatusLabel2.Text = "Waiting for parallel ping"; toolStripStatusLabel2.Visible = true; System.Threading.Thread.Sleep(speed1); } }
public MyWorkerArgs(serverControl server, networkProtocol np) { srv = server; netP = np; }
private void connectToolStripMenuItem_Click(object sender, EventArgs e) { networkProtocol np = new networkProtocol(); np.serverList = servers; if (!backgroundWorker1.IsBusy) { backgroundWorker1.RunWorkerAsync(np); toolStripProgressBar1.Visible = true; toolStripStatusLabel2.Text = "Waiting for ping"; toolStripStatusLabel2.Visible = true; } }