Long work (or forever) on Windows Azure

I need to write some data to the database every 50 seconds or so. It looks like a Windows service that runs in the background and quietly does its job. Starting and stopping is not an option in my case, since I need a small amount of previously inserted data that will be stored in memory. What is the best solution for this when using Windows Azure or AWS?

Thank.

+5
source share
3 answers

In Windows Azure, you can choose the Web or Worker role (both mostly Windows 2008 Server R2 and SP2) and have a specific time type, as suggested by @Lucifure. You can also run a scheduler, such as Quartz.net, or use Windows Azure queues or service bus queues to display messages at specific times. Nevertheless: you cannot have the task “forever” in the given instance of the role, since periodically your virtual machine instances will be rebooted (for example, to service the host operating system every month). When you turn off features, you’ll receive a notification that you can process with shutdown notifications in Stopping()orOnStop(). If you have multiple instances, you can use a scheduler or queue to ensure that your events are still triggered every 50 seconds or so, and process them through multiple instances (but only by one instance at any given time).

To store information in memory, one idea is to store this information in a cache. You have 2 options:

  • A distributed (shared) cache service that has been around for some time. It works regardless of role instances.
  • A memory cache introduced only in June 2012. Assuming you have multiple instances, the cache is distributed across those instances. You can even run a cache inside the memory of your existing roles.

More information on caching here .

StackOverflow Quartz.net Windows Azure, .

+7

You can configure System.Threading.Timer to run every 50 seconds and do its job whenever an event occurs.

+1
source

All Articles