Guest User

Untitled

a guest
Sep 14th, 2018
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.25 KB | None | 0 0
  1. Process Operations (Monitoring)
  2. private void timer_ProcessCheck_Tick(object sender, EventArgs e)
  3. {
  4. Process[] tmpArray = Wow_getCurrentlyRunning(); // this returns Process[]
  5. if (comboBox_processes.Items.Count == 0)
  6. {
  7. if (tmpArray.Count() > 0)
  8. for (int Index = 0; Index < tmpArray.Count(); Index++)
  9. Add(tmpArray[Index]); // adding to combobox
  10. }
  11. else
  12. {
  13. if (tmpArray.Count() > comboBox_processes.Items.Count)
  14. {
  15. List<Process> result;
  16. /*Diff compares the two array, and returns to result variable.*/
  17. if (Diff(tmpArray, comboBox_processes, out result))
  18. foreach(Process proc in result)
  19. Add(proc); // adding to combobox
  20. }
  21. }
  22. }
  23.  
  24. public bool Wow_differsFrom(Process[] current, ComboBox local, out List<Process> diff)
  25. {
  26. List<int> diffIndex = new List<int>();
  27.  
  28. foreach (Process proc in current)
  29. diffIndex.Add(proc.Id);
  30.  
  31. for (byte Índex = 0; Índex < current.Count(); Índex++)
  32. {
  33. for (byte Index = 0; Index < local.Items.Count; Index++)
  34. {
  35. if (current[Índex].Id == (local.Items[Index] as Process).Id)
  36. {
  37. diffIndex.Remove(current[Índex].Id);
  38. break;
  39. }
  40. }
  41. }
  42.  
  43. diff = new List<Process>();
  44.  
  45. for (int x = 0; x < current.Count(); x++)
  46. for (int i = 0; i < diffIndex.Count; i++)
  47. if (current[x].Id == diffIndex[i])
  48. diff.Add(current[x]);
  49.  
  50. if (diff.Count == 0)
  51. return false;
  52. return true;
  53. }
  54.  
  55. private void Wow_exitedEvent(object o, EventArgs e)
  56. {
  57. RemoveCBItem(comboBox_processes, (o as Process).Id); // this will remove the process from combobox, also threadsafe.
  58. }
  59.  
  60. //Somewhere in Form_Load
  61. combobox.DisplayMember = "Name";//name of the property in your MyProcessInfo class
  62. combobox.ValueMember = "Id";//name of the property in your MyProcessInfo class
  63.  
  64. //In your timer.Tick handler
  65. combobox.DataSource = Wow_getCurrentlyRunning().Select(p=>new MyProcessInfo(p.Id, p.Name)).ToList();
Add Comment
Please, Sign In to add comment