void onUpdateHandler(ProcessStatsEventArgs procStats) { //anyone listening? if (this.updateEvent == null) { return; } this.updateEvent(this, procStats); }
void addData(ProcessStatsEventArgs procStats) { if (this.dataGrid1.InvokeRequired) { addDataCallback d = new addDataCallback(addData); this.Invoke(d, new object[] { procStats }); } else { dataGrid1.SuspendLayout(); //dtProcesses.Rows.Clear(); foreach (KeyValuePair <string, ProcessStatistics.process_statistics> ps in procStats.procStatistics) { object[] o = new object[] { ps.Value.processID, ps.Value.sName, ps.Value.procUsage.user, ps.Value.procUsage.kernel, ps.Value.dateTime, ps.Value.duration }; DataRow dr; //check if data already exists dr = dsProcesses.Tables[0].Rows.Find(ps.Value.processID.ToString()); if (dr == null) { //add a new row dr = dtProcesses.NewRow(); dr.ItemArray = o; dtProcesses.Rows.Add(dr); } else { dr.ItemArray = o; } } dataGrid1.Refresh(); dataGrid1.ResumeLayout(); //object[] o = new object[7]{ procUsage.procStatistics. .procStatistics. [i].sApp, eventEntries[i].sArg, eventEntries[i].sEvent, // eventEntries[i].sStartTime, eventEntries[i].sEndTime, eventEntries[i].sType, eventEntries[i].sHandle }; } }
void pInfo_updateEvent(object sender, ProcessStatsEventArgs eventArgs) { setText(ProcessStatistics.dumpProcStats(eventArgs)); addData(eventArgs); }