code_junkie

Why am I getting this error:“Cross-thread operation not valid: Control lbFolders accessed from a thread other than the thread it was created on.”?

Nov 11th, 2011
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.67 KB | None | 0 0
  1. prgAll.Maximum = lbFolders.SelectedItems.Count;
  2.  
  3. foreach (string dir in lbFolders.SelectedItems)
  4.  
  5. lblStatus.Invoke((Action)(() => lblStatus.Text = counter.ToString()));
  6.  
  7. lblTest.Invoke((MethodInvoker)(delegate()
  8. {
  9. lblTest.Text = i.ToString();
  10. }));
  11.  
  12. prgAll.Maximum = lbFolders.SelectedItems.Count;
  13.  
  14. void SetMax()
  15. {
  16. if (prgAll.InvokeRequired)
  17. {
  18. prgAll.BeginInvoke(new MethodInvoker(SetMax));
  19. return;
  20. }
  21.  
  22. prgAll.Maximum = lbFolders.SelectedItems.Count;
  23. }
  24.  
  25. private void RunMe()
  26. {
  27. if (!InvokeRequired)
  28. {
  29. myLabel.Text = "You pushed the button!";
  30. }
  31. else
  32. {
  33. Invoke(new ThreadStart(RunMe));
  34. }
  35. }
Add Comment
Please, Sign In to add comment