How can i report muiltple reportprogress values from backgroundworker dowork event to a...

  • Thread starter Thread starter Chocolade1972
  • Start date Start date
C

Chocolade1972

Guest
First i added this class:


public class MyProgress
{
public string Id { get; set; }
public string Progress { get; set; }
}



Then the dowork event:

private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
{
BackgroundWorker worker = sender as BackgroundWorker;

if ((worker.CancellationPending == true))
{
e.Cancel = true;
}
else
{
List<IntPtr> intptrs = GetProcessesIntptrList();
for (int x = 0; x < intptrs.Count ; x++)
{
GetProcessInfo(intptrs[x]);
}
while (true)
{
List<MyProgress> prog = new List<MyProgress>();

prog = new List<MyProgress>();

procList = Process.GetProcesses().ToList();
for (int i = 0; i < procList.Count; i++)
{
Process[] processes = Process.GetProcessesByName(procList.ProcessName);
PerformanceCounter performanceCounter = new PerformanceCounter();
performanceCounter.CategoryName = "Process";
performanceCounter.CounterName = "Working Set - Private";//"Working Set";
performanceCounter.InstanceName = processes[0].ProcessName;

prog.Add(new MyProgress { Id = procList.ProcessName, Progress = ((uint)performanceCounter.NextValue() / 1024).ToString("N0") });

worker.ReportProgress(0, prog);
}
}
}
}



And last the backgroundworker progresschanged event where i want to add the values of each process to the datagridview1 rows under cell 3.


private void backgroundWorker1_ProgressChanged(object sender, ProgressChangedEventArgs e)
{
foreach (MyProgress p in (e.UserState as List<MyProgress>))
{
currentRow.Cells[3].Value = p.Progress;
dataGridView1.Rows.Add(
p.Progress);
}
}

The variable currentRow not exit yet. And i know that cell 3 is where i want to add all the rows of the processes values.

And i also dont know how many rows there should be.

Continue reading...
 
Back
Top