ThreadPool in .NET is a queue-based workgroup pool, however it is used by ASP.NET internal hosting, so if you try to use ThreadPool more, you can slow down the performance of the web server.
So, you have to create your own thread, mark it as background and give it a poll every few seconds for the availability of work.
: :
Table: JobQueue
JobID (bigint, auto number)
JobType (sendemail,calcstats)
JobParams (text)
IsRunning (true/false)
IsOver (true/false)
LastError (text)
JobThread .
class JobThread{
static Thread bgThread = null;
static AutoResetEvent arWait = new AutoResetEvent(false);
public static void ProcessQueue(Job job)
{
job.InsertInDB();
if(bgThread==null){
bgThread = new Thread(new ..(WorkerProcess));
bgThread.IsBackground = true;
bgThread.Start();
}
else{
arWait.Set();
}
}
private static void WorkerProcess(object state){
while(true){
Job job = GetAvailableJob(
IsProcessing = false and IsOver = flase);
if(job == null){
arWait.WaitOne(10*1000);
continue;
}
job.IsRunning = true;
job.UpdateDB();
try{
}
catch(Exception ex){
job.LastError = ex.ToString();
job.UpdateDB();
}
job.IsRunning = false;
job.IsOver = true;
job.UpdateDB();
}
}
}
, ASP.NET , , , Bitmap, ASP.NET , Windows .
Windows, , ASP.NET Windows Service WCF Mutex.
MSMQ
MSMQ , , . MSMQ, , MSMQ , , . . , Win32, .