0
How do I create a thread that runs a function, wait 1 second and loop again until the program shuts down?
0
How do I create a thread that runs a function, wait 1 second and loop again until the program shuts down?
2
I don’t know what your role will do but this would be a Loop Thread.
using System.Threading;
...
Thread thread = new Thread(tarefa);
thread.Start();
public void tarefa()
{
while(true)
{
...
anotherFunction();
Thread.Sleep(1000);
}
}
public void anotherfunction()
{
...
}
Summarizing Voce creates a Thread pointing to the task() method that loops (in this case eternal) the anotherfunction() method and waits for a second to run again
Browser other questions tagged c# thread loop
You are not signed in. Login or sign up in order to post.
That’s what I was wanting to do, I just forgot to use the Sleep function.
– Vinicius Fernandes
For beauty, do not forget to use a Thread.Abort(); in your program, otherwise this Thread will be "open" forever, in a simple use may not make a difference, but on a large scale, as for example use it for communication, Forgetting to abort overloads processing.
– Elliot Alderson