1.11M Members

Wait or pause method in C#

 
0
 

Hello everyone!
I know how to use a Timer class:

static void Main(string[] args)
        {
            System.Timers.Timer MyTimer = new System.Timers.Timer();
            MyTimer.Elapsed += new System.Timers.ElapsedEventHandler(MyTimer_Elapsed);
            MyTimer.Interval = 2000;
            MyTimer.Enabled = true;
            //etc.
        }

        static void MyTimer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
        {
            //do something every 2 seconds
        }

What I like to do is draw something every 2 secs during a draw method in a loop like:
>while condition true
> Draw object
> Wait 2 secs
>end loop after condition false

I could use a very long empty for loop as a wait method, is there a better way?
Have looked around here and there but found nothing usefull.
Any help (as always) is greatly appreciated:)

 
1
 

If you don't mind that the thread will halt for 2 seconds, you can use Thread.Sleep(2000).

 
0
 

Thanks DdoubleD!
That really helps. I was probably looking for the wrong words like pause and wait.:idea:

Question Answered as of 4 Years Ago by DdoubleD
 
0
 

Thanks DdoubleD!
That really helps. I was probably looking for the wrong words like pause and wait.:idea:

I actually had flashbacks of that same thinking in the past... I was just hoping it was that simple.:P

 
0
 

Thanks to Intellisence I was even able to figure out I needed using System.Threading; Thanks again D!

Isn't it about time forums rewarded their contributors?

Earn rewards points for helping others. Gain kudos. Cash out. Get better answers yourself.

It's as simple as contributing editorial or replying to discussions labeled or OP Kudos

You
This question has already been solved: Start a new discussion instead
Post:
Start New Discussion
View similar articles that have also been tagged: