Comic Sans MS Lover
Comic Sans MS Lover

Reputation: 1729

How to execute a block of code with 1 second intervals?

I need to execute a block every 1 second, but it needs to be in the same thread. This means, from what I understand, that I can't make the use of a timer class.

Is there a way to do what I want?

Upvotes: 0

Views: 2588

Answers (1)

Brandon Cuff
Brandon Cuff

Reputation: 1478

Create a thread and write a loop like so -

while(true)
{
    // do something
    Thread.sleep(1000);
}

Upvotes: 3

Related Questions