Timing Question

Hello,
I've asked this question before but for some reason or another, my post was deleted. So I decided to try and repost something similar.Anyway, for a long time I've been wondering if it's possible to do certain actions in a loop every once in a while like so:

private: System::Void button1_Click(System::Object^  sender, System::EventArgs^  e)
         {
                while (condition)
             {
                 Thread^ sleeper;
                 int i;
                 sleeper->Sleep(200);
                 button1->Enabled = false;
             }
         }

But it just doesn't work...

With Thanks,
                    Gal Beniamini.


Answer this question

Timing Question

  • hieronymus

    Hello Martin, thanks for the answer but I don't really get it...
    First of all, I thought that when I wrote -Thread^ sleeper- it created a new thread, and then I used it, so doesn't that mean I used a second thread
    Secondly, how do I initiate Message Pumping And... What do you mean by -Also the sleeper thread is not a valid object. You just declared it as a handle but this handle is null!-

    With Thanks,
                        Gal Beniamini.

  • jornjorn

    1. If you want to do any actions asynchonious you should use a second thread.
    2. Your sample code will set a button to disabled every 200 msec. But any how the user interface will not accept any message because no message pumping wil occure. Also the sleeper thread is not a valid object. You just declared it as a handle but this handle is null!



  • Stan Burton

    I am a new user of visual c++.

    Look this link : http://forums.microsoft.com/msdn/ShowPost.aspx PostID=66677

    Maybe it can help you...

    let's stay in contact...

  • Timing Question