Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set timer on worker role?

Tags:

azure

How to create a Worker role in Azure using timer?

like image 549
Bhaskara varma Dandu Avatar asked Mar 17 '26 09:03

Bhaskara varma Dandu


1 Answers

If you create a new worker role, the template code generates a Run() method for you. In that Run() method, you'll see the easiest way to create a timer:

while (true)
{
    Thread.Sleep(10000);
    Trace.WriteLine("Working", "Information");
}

So in this example, the thread sleeps for 10 seconds, then wakes up and emits a log statement. You can change the time interval to be anything you want, and you then call whatever custom code you have after Thread.Sleep() returns.

like image 134
David Makogon Avatar answered Mar 19 '26 11:03

David Makogon



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!