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?

2

1 Answer

Create a thread and write a loop like so -

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Alexander Ross

Alexander Ross

Gaming, Esports & Interactive Media Writer

Alexander Ross has covered the video game industry for a decade, writing deep dives on game design, esports tournaments, VR developments, and gaming culture.

Share this article
Twitter Facebook Pinterest