Advertisement
Guest User

Untitled

a guest
Jun 26th, 2019
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.86 KB | None | 0 0
  1. public partial class Form1 : Form
  2. {
  3.  
  4. public delegate void SafeRefresh();
  5. public SafeRefresh myDelegate;
  6. private Form1 currentForm;
  7. Thread scriptThread;
  8.  
  9. public Form1()
  10. {
  11. InitializeComponent();
  12. currentForm = this;
  13. myDelegate = new SafeRefresh(SafeRefreshAllMethod);
  14.  
  15. }
  16. private async void button_script_Click(object sender, EventArgs e)
  17. {
  18. scriptThread = new Thread( () => SomeClass.RunScript(currentForm));
  19. scriptThread.Start();
  20. }
  21.  
  22. public void SafeRefreshAllMethod()
  23. {
  24.  
  25. listBox.DataSource = null;
  26. listBox.Refresh();
  27. listBox.DataSource = Global.ListAllItems;
  28. listBox.Refresh();
  29. }
  30.  
  31.  
  32. public void listBox_DrawItem(object sender, DrawItemEventArgs e)
  33. {
  34. Brush myBrush;
  35. if (Global.ListItemsDisconnected.Contains(Global.ListAllItems[e.Index] ))
  36. {
  37. myBrush = Brushes.Gray;
  38. }
  39. else if (Global.ListItemsConnected.Contains(Global.ListAllItems[e.Index]))
  40. {
  41. myBrush = Brushes.Green;
  42. }
  43. else
  44. {
  45. myBrush = Brushes.Black;
  46. }
  47.  
  48. e.DrawBackground();
  49. e.Graphics.DrawString(listBox.Items[e.Index].ToString(), listBox.Font, myBrush, e.Bounds);
  50. }
  51.  
  52. }
  53.  
  54. class SomeClass {
  55. public static void RunScript(Form1 theForm)
  56. {
  57.  
  58. foreach (string item in Global.ListAllItems)
  59. {
  60.  
  61. //some code that works with the items on list
  62. //if disconnected : adds to Global.ListItemsDisconnected
  63. //if connected: adds it to Global.ListItemsConnected
  64.  
  65. theForm.Invoke(theForm.myDelegate);
  66.  
  67.  
  68. }
  69. }
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement