Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public partial class Form1 : Form
- {
- public delegate void SafeRefresh();
- public SafeRefresh myDelegate;
- private Form1 currentForm;
- Thread scriptThread;
- public Form1()
- {
- InitializeComponent();
- currentForm = this;
- myDelegate = new SafeRefresh(SafeRefreshAllMethod);
- }
- private async void button_script_Click(object sender, EventArgs e)
- {
- scriptThread = new Thread( () => SomeClass.RunScript(currentForm));
- scriptThread.Start();
- }
- public void SafeRefreshAllMethod()
- {
- listBox.DataSource = null;
- listBox.Refresh();
- listBox.DataSource = Global.ListAllItems;
- listBox.Refresh();
- }
- public void listBox_DrawItem(object sender, DrawItemEventArgs e)
- {
- Brush myBrush;
- if (Global.ListItemsDisconnected.Contains(Global.ListAllItems[e.Index] ))
- {
- myBrush = Brushes.Gray;
- }
- else if (Global.ListItemsConnected.Contains(Global.ListAllItems[e.Index]))
- {
- myBrush = Brushes.Green;
- }
- else
- {
- myBrush = Brushes.Black;
- }
- e.DrawBackground();
- e.Graphics.DrawString(listBox.Items[e.Index].ToString(), listBox.Font, myBrush, e.Bounds);
- }
- }
- class SomeClass {
- public static void RunScript(Form1 theForm)
- {
- foreach (string item in Global.ListAllItems)
- {
- //some code that works with the items on list
- //if disconnected : adds to Global.ListItemsDisconnected
- //if connected: adds it to Global.ListItemsConnected
- theForm.Invoke(theForm.myDelegate);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement