views:

174

answers:

2

I have an ASP.Net application that needs needs to have some work performed by another machine. To do this I am leaving a message on queue visible to both machines. When the work is done a message is left on second queue.

I need the ASP.Net application to check the second queue periodically to see if any of the tasks are complete.

Where is the best place to but such a loop? Global.asax?

I remember reading somewhere that you can get a function called after an interval. Would that be suitable?

+1  A: 

I assume that this is done on a regular basis, and that some other process puts the items on the queue?

If that is the case, you might put something in Global.asax that on application start creates a separate thread that simply monitors the queue, you could use a timer to have that thread sleep for X seconds, then check for results.

Mitchel Sellers
+1  A: 

To achieve periodical tasks on asp.net, I've found two acceptable approaches:

  1. Spawn a thread during Application_Start at global.asax, in a while loop (1) Do the work (2) Sleep the thread for an interval.
  2. Again in Application_Start, insert a dummy item into asp.net cache, expires in a certain interval and give that cache item a callback to be called when it's expired. In that callback, you can do the work and insert the cache item back the same way.

In both ways, you need to make sure that your thread keeps working even if there happens an error. You may place a restore code in SessionStart and BeginRequest to check your thread or cache item is there, and renew it if something has happened to it.

Gorkem Pacaci