How do I create a thread that executes a function, waits 1 second, and then re-runs in loop until the program quits?
How do I create a thread that executes a function, waits 1 second, and then re-runs in loop until the program quits?
I do not know what your function will do but it would be a Thread in Loop.
using System.Threading;
...
Thread thread = new Thread(tarefa);
thread.Start();
public void tarefa()
{
while(true)
{
...
anotherFunction();
Thread.Sleep(1000);
}
}
public void anotherfunction()
{
...
}
In short, you create a Thread pointing to the task () method that executes in loop (in this case eternal) anotherfunction () method and waits a second to execute again