c# - Best way to implement windows service as "worker" -


i have asp .net page allows users start programs. these programs , parameter stored in database , windows service executes these programs. programs dlls implements iplugin interface, can add them @ runtime (the dlls loaded @ runtime can add them @ runtime without compiling or restarting service).

i created asp .net page, more 10 programs (plugins) , windows service. running fine, think implementation of windows service bad.

the windows service periodically queries database , executes needed program if gets new entry. service can run multiple programs in parallel (at moment 3 programs).

currently service method looks this:

 while (alive)         {                 // gets running processes database                 processes = proc.getrunningprocs();                  // if there less 3 processes running ,                 // process in queue                 if (readytorun())                 {                     // next program queue, sets status                      // runnig , update entry in database                     proc.procdata proc = getnextproc();                     proc.status = proc.procstatus.running;                     proc.update(proc);                      // create new thread , execute program                     thread t = new thread(new parameterizedthreadstart(executeproc));                     t.isbackground = true;                     t.start(proc);                 }              thread.sleep(1000);         } 

i have method queries database entries status 'canceling' (if user cancels program, status set 'canceling') , thread.abort().

is there better practice? using tasks cancel mechanism or whole concept (storing processes in database (program name, parameter, status,... , querying information periodically) wrong?

as alternative can use existing libraries purposes quartz.net http://www.quartz-scheduler.net/. takes care job persistence, job scheduling , many other things. must create adapter , put windows service.


Comments

Popular posts from this blog

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

linux - disk space limitation when creating war file -

How to provide Authorization & Authentication using Asp.net, C#? -