views:

103

answers:

3
+2  Q: 

Sort of scheduler

I need to implement something. Something that could do some certain task in my program. For example every ten seconds, write something into a log in a file. Of course it suppose to run in a background thread.

Where should I dig? I am not so familiar with multithreading. I've heard about BackgroundWorker class, but I'm not sure if it is appropriate here..

A: 

You could use the backgroundworker class for this, but it sounds like you just need to use Timer.

consultutah
could you give me a link to some example? thanks
Ike
+4  A: 

Use System.Threading.Timer, it will run a task in a ThreadPoool thread. That is the most efficient way for this.

Here is an example, every 10 seconds:

Timer aTimer = new System.Threading.Timer(MyTask, null, 0, 10000);

static void MyTask(object state)
{
  ...
}
Henk Holterman
+1  A: 

Actually for WPF DispatcherTimer would be much better than the Async timer.

Paul Betts