Threading in a Web App - Shared Hosting Environment

johnmc33
johnmc33 used Ask the Experts™
on
Hi,
I have a .NET 2.0 web application on shared hosting environment which is hooked to a SQL Server 2005 database.

I want to give my users an instant response and let a thread handle the processing in the background.  The design in place does the following:

For each user who logs into site this will happen
{
1. User logs into site and creates X messages.
2. Write each message to a record to a MessageQ table for this user in database
3. Return control to user and start a thread which reads MessageQ entries for this user and processes.
}
My question is.. ... Does this design look ok?

Each user accessing the system will create a thread for their messages so potentially N users could have N threads all accessing the MessageQ table at the same time.

That is my concern.

John
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Technical SEO Consultant
Commented:
You may want just one thread that processes all users message. You can keep the thread running at all times and have it check the queue say every second.

Author

Commented:
So just spark off a worker thread at application_start time which loops through the table ... processes the message and then sleeps for a couple of seconds?



Tony McCreathTechnical SEO Consultant

Commented:
That sounds just right. I often do a check every once in a while to check the thread is still running. e.g. on each request.

Author

Commented:
and finally ...

As more than 1 user request could be writing to the messageQ table at the same time, I have made all inserts statements to the messageQ table using transactional stored procedures.

This means writing the to table will be threadsafe .... right?...

Thank you so much for the help on this.
Tony McCreathTechnical SEO Consultant

Commented:
If its a single insert then you should be safe anyhow but no harm in doing things fully.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial