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

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

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.

You Might Also Like