How to create thread in loop in C #?

0

How do I create a thread that executes a function, waits 1 second, and then re-runs in loop until the program quits?

    
asked by anonymous 08.08.2016 / 22:18

1 answer

2

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

    
09.08.2016 / 14:15