1,105,427 Community Members

Wait or pause method in C#

Member Avatar
ddanbe
Posting Expert
5,354 posts since Oct 2008
Reputation Points: 2,066 [?]
Q&As Helped to Solve: 908 [?]
Skill Endorsements: 46 [?]
Featured
 
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:)

Member Avatar
DdoubleD
Posting Shark
984 posts since Jul 2009
Reputation Points: 315 [?]
Q&As Helped to Solve: 235 [?]
Skill Endorsements: 5 [?]
 
1
 

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

Member Avatar
ddanbe
Posting Expert
5,354 posts since Oct 2008
Reputation Points: 2,066 [?]
Q&As Helped to Solve: 908 [?]
Skill Endorsements: 46 [?]
Featured
 
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
Member Avatar
DdoubleD
Posting Shark
984 posts since Jul 2009
Reputation Points: 315 [?]
Q&As Helped to Solve: 235 [?]
Skill Endorsements: 5 [?]
 
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

Member Avatar
ddanbe
Posting Expert
5,354 posts since Oct 2008
Reputation Points: 2,066 [?]
Q&As Helped to Solve: 908 [?]
Skill Endorsements: 46 [?]
Featured
 
0
 

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

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