2012-07-18 79 views
0
public void processloader(object temp) 
{ 

    Process[] processes = null; 
    try 
    { 
     processes = Process.GetProcesses(); 
    } 

    catch (Exception ex) 
    { 
     MessageBox.Show(ex.Message); 
     Application.Exit(); 
     return; 
    } 
    listView1.BeginUpdate(); 
    listView1.Clear(); 
    int threadscount = 0; 
    listView1.Items.Clear(); 
    foreach (Process p in processes) 
    { 
     try 
     { 
      string[] prcdetails = new string[] { p.ProcessName, p.Id.ToString(), p.StartTime.ToShortTimeString(), p.PriorityClass.ToString(), (p.WorkingSet64/1048576).ToString() + "Mb", p.Threads.Count.ToString() }; 
      ListViewItem proc = new ListViewItem(prcdetails); 
      listView1.Items.Add(proc); 
      threadscount += p.Threads.Count; 
     } 
     catch { Console.WriteLine(p); } 
    } 
    statusBar1.Panels[0].Text = "Processes : " + processes.Length.ToString(); 
    statusBar1.Panels[1].Text = "Threads : " + (threadscount + 1).ToString(); 
    listView1.EndUpdate(); 
    listView1.Refresh(); 


} 

這裏是refreher塊,我每秒通過使用System.threading.timer()調用這個函數。我需要像原始taskmanager刷新功能的解決方案,任何人都可以爲此提供幫助嗎?請提供一些示例代碼。提前致謝!當新進程進入時自動刷新列表視圖

+0

可能重複[C#的Process Monitor(http://stackoverflow.com/questions/1986249/c-sharp-process-monitor) – 2012-07-18 17:05:43

回答