iLemming
iLemming

Reputation: 36166

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..

Upvotes: 2

Views: 195

Answers (3)

Ana Betts
Ana Betts

Reputation: 74654

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

Upvotes: 1

Henk Holterman
Henk Holterman

Reputation: 273179

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)
{
  ...
}

Upvotes: 4

ConsultUtah
ConsultUtah

Reputation: 6809

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

Upvotes: 0

Related Questions