0

I have one main form that starts on program in program.cs as Application.Run(new Form1());. It opens object of 2 different forms as:

Form2 obj1 = new Form2();
obj2.Show();

Form3 obj2 = new Form3();
obj3.Show();

Each form has Thread.Sleep(10000) code but the problem is that on one's Thread.Sleep execution, whole programs sleeps. I thought if one form's Thread.Sleep runs, it will not stop other form and will not affect those.

halfer
  • 19,824
  • 17
  • 99
  • 186
Computer User
  • 2,839
  • 4
  • 47
  • 69

1 Answers1

6

All GUI components run on a single GUI thread therefore if you sleep that thread everything running on that thread sleeps, which in your case means all of your forms.

If you need a particular form to wait for something to happen then there are various ways of doing that, however, you need to be a bit more clear in your question as to what exactly it is you are waiting for.

James
  • 80,725
  • 18
  • 167
  • 237
  • You need to use threading. This might help you: http://stackoverflow.com/questions/661561/how-to-update-the-gui-from-another-thread-in-c – Samich Jun 17 '13 at 13:36
  • 1
    @Samich yes you do - but my point is the OP hasn't made it clear as to *why* he needs the form to sleep in the first place, there are possibly neater ways of doing what it is he needs i.e. a `Timer`. Also, the question you link to isn't even on the same topic it refers to how to update a GUI from another thread... – James Jun 17 '13 at 13:37
  • Hey, it wasn't comment to your answer, it just addition to your comment. Sorry if I wasn't clear. :) – Samich Jun 17 '13 at 13:45
  • @Samich no worries, you should put your comment on the actual question then and not my answer as the OP would get a notification. – James Jun 17 '13 at 13:48
  • @james, can you also please reply on my next question: http://stackoverflow.com/questions/17150298/opening-a-form-multiple-times-from-a-static-class-which-is-called-from-different – Computer User Jun 17 '13 at 14:58
  • @James, can you also please reply on my next question: http://stackoverflow.com/questions/17150298/opening-a-form-multiple-times-from-a-static-class-which-is-called-from-different – Computer User Jun 17 '13 at 14:58