2

I have an application that dynamically loads and runs DLLs writen by users. It has a scheduling engine that runs on a timer and checks which "rules" (dlls) to run. Each rule is started on its own thread using:

private void OnTimer(...)
{
   timer.stop();
   ...
   foreach(RuleData ruleData in RulesToRun)
      ThreadPool.QueueUserWorkItem(new System.Threading.WaitCallback(ExecuteRule), ruleData);
   _asyncOpsAreDone.WaitOne();
   timer.start();
}

and when the async operations are done, the program waits for the schedualing timer to tick and run another loop.

Problem is that sometimes users write dlls that take a lot of time to run.

  • If I'll wait: This will postpone the next timer tick (as it is stoped while executing and started again after)
  • If I wont wait: I'm looking for unknown number of rules running in parallel, finishing my pool of application users.

If you would take into consideration that one rule execution might hang, My choise is between: Synch - hang all rules, or Asynch - dry resource pools.

I seriously thought about giving rule execution a timeout, but .Abort() isn't so popular: Timeout Pattern - How bad is Thread.Abort really?

And Parallel progrming solution for Cancelation of task, Involves writing "ThrowIfCancellationRequested();" in the dll execution (which I don't have source code for) http://msdn.microsoft.com/en-us/library/dd997396.aspx

Community
  • 1
  • 1
user355289
  • 1,100
  • 2
  • 13
  • 23
  • What language is this? Please add a language tag. – Gray Aug 01 '12 at 21:41
  • Interesting problem - your design pattern is generating something akin to the old Windows 3.x cooperative multi-tasking, where one misbehaving application failing to yield the cpu will hang the others (here they won't hang, but they won't restart until the misbehaving DLL finishes) - What about not waiting for all DLLs to finish, and restarting only the ones that have completed? Is that an option? –  Aug 01 '12 at 22:01
  • FWIW, for scheduling Quartz.net is very useful. http://quartznet.sourceforge.net/ – James Manning Aug 01 '12 at 23:17
  • I could just restart the ones that are completed, but than I'm left with the same problem of resources for the ones that hang forever. – user355289 Aug 02 '12 at 05:27
  • 1
    What exactly is the question? – svick Aug 02 '12 at 09:00

1 Answers1

0

The third comment by "sgorozco" helped me the most, I've chosen to continue running rules asyncronously, but skip the ones that are already in process this way I:

  • Get the job done on time for other rules that are writen correctly.

  • Skip jobs that are stuck.

  • Avoid killing threads and leaving broken memory garbage.

user355289
  • 1,100
  • 2
  • 13
  • 23