Link to home
Start Free TrialLog in
Avatar of johnmc33
johnmc33Flag for United States of America

asked on

Threading in a Web App - Shared Hosting Environment

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
ASKER CERTIFIED SOLUTION
Avatar of Tony McCreath
Tony McCreath
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of johnmc33

ASKER

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?



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.
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.
If its a single insert then you should be safe anyhow but no harm in doing things fully.