WinForms start thread that can access the GUI


/ Published in: C#
Save to your folder(s)



Copy this code and paste it in your HTML
  1. using System.Threading;
  2.  
  3. private void btnStart_Click(object sender, EventArgs e)
  4. {
  5. Thread t = new Thread(new ThreadStart(this.AsyncGetResults));
  6. t.Start();
  7. }
  8.  
  9. private void AsyncGetResults()
  10. {
  11.  
  12. // Do some not-GUI-touching stuff
  13. // ...
  14.  
  15. // So some GUI-touching stuff
  16. if (panellWait.InvokeRequired)
  17. {
  18. panelWait.Invoke(new MethodInvoker(delegate
  19. {
  20. panelWait.Visible = true;
  21. }));
  22. }
  23.  
  24. // Do some other not-GUI-touching stuff
  25. // ...
  26. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.