Posted By

yasbas on 09/01/10


Tagged


Versions (?)

Who likes this?

2 people have marked this snippet as a favorite

maxbaines
Tyster


WinForms start thread that can access the GUI


 / Published in: C#
 

  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  

You need to login to post a comment.