How to handle this (Pros help)

G

Guest

Hi,
I want to MSMQ in my ASP.net app. The app would pass the job to MSMQ and the
a service comp would pick it up from there and execute the job in database.
Now the stored proc in the database takes a while so is there a way not to
have the service comp not to pick up another job from MSMQ until the sp is
completed in the database. I want only one job to executed at a time because
multiple instance of the sp will use up a lot o ram on my server and really
slow the database.

Thanks
 
K

Kevin Spencer

Okay, basically, you need to write a Windows Service. You want to Service to
process one message at a time. So, here is my thinking aobut how to do this.
Have the Service use a timer. The timer has an event handler that fetches a
message from the queue and executes the Stored Procedure. The event handler
method will not return until the SP is executed. So, to prevent multiple
instances of the event handler from occurring, have the event handler stop
the timer, execute the SP, and just before returning, restart the timer.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
Sometimes you eat the elephant.
Sometimes the elephant eats you.
 
K

Kevin Spencer

After thinking a bit more:

Another possibility is to use a single method that runs continuously. It
executes an infinite loop. The loop fetches a messge, calls the SP, and will
not finish of course until the SP has finished executing. Therefore, there
is no need for a timer at all. Just call the method in the OnStart method of
the Service. Much better I think.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
Sometimes you eat the elephant.
Sometimes the elephant eats you.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top