Hi,

I'm trying to find out how to call a method from another class every 0.5 seconds until I tell it to stop using a function from the same class (the class that is doing the calling). Does anyone know if this is even possible? I've done a few Internet searches and tried to write the code but I've come up with nothing substantial. Could anyone please show me how to do this. Some sample code would be appreciated. This is just highlighting my programming weaknesses. Thank you very much.

SasukeUchiha.

All the links Vernon pointed you towards are Timer related, it seems like. His may be a better solution than what I'll show you, but there is another way to do it pretty easily:

Use Thread.sleep(milliSeconds);
Then call whatever method it is you wanted to run every five seconds. You can do this in a while loop, and one simple way you could exit the while loop is with a boolean that changes to false when you want to stop calling the method.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.