public ThreadContext(Thread threadMgr, MonitorThread threadObject) { this.threadMgr = threadMgr; this.threadObject = threadObject; }
//Monitor private void agregarToolStripMenuItem_Click(object sender, EventArgs e) { TaskMonitor.Sources.Monitor newMonitor = null; using (AddMonitorForm addMonitorForm = new AddMonitorForm(this)) { var ans = addMonitorForm.ShowDialog(); if (ans == System.Windows.Forms.DialogResult.OK) { newMonitor = addMonitorForm.ReturnValue; } } if (newMonitor != null) { MonitorThread newMonitorThread = new MonitorThread(newMonitor, monitoring); Thread newThreadMgr = new Thread(new ThreadStart(newMonitorThread.MainMethod)); if (newMonitor.mode == Mode.service) { //Crea el monitor y su hilo newThreadMgr.Name = "ThreadService" + serviceMonitorThreads.Count.ToString(); serviceMonitorThreads.Add(new ThreadContext(newThreadMgr, newMonitorThread)); newThreadMgr.Start(); //Lo agrega al datagrid this.statusReporter.AddServiceMonitorData((ServiceMonitor)newMonitor, this); } else { //Crea el monitor y su hilo newThreadMgr.Name = "ThreadProcess" + processMonitorThreads.Count.ToString(); processMonitorThreads.Add(new ThreadContext(newThreadMgr, newMonitorThread)); newThreadMgr.Start(); //Lo agrega al datagrid this.statusReporter.AddProcessMonitorData((ProcessMonitor)newMonitor, this); } } }