runtime registration in the task queue

Feb 17, 2010 at 10:52 AM

Hi,

great work. I would like to know if we can register the task in the runtime.

use the "send mail" for example, in the pdf document, we have to compile the library assembly and register, how can we do it runtime.

1/ we have a user list (with email field/property of cource)

2/ select the users and try to send email to these users.

I want to set the task settings in my program, e.g., time, schedule...

after this, these ready-to-sent mails will be shown  in the task queue....

Coordinator
Feb 18, 2010 at 9:55 AM

Hi,

you could do that: just look at the code behind the "register" contextual menu, you'll see that the only thing you have to do is

  • ConfigurationManagement.Tasks.Add({TaskName}, {AssemblyName}, {AssemblyPath}, {ClassName})

But...

  • Once the assembly is loaded into memory, it cannot be unloaded (there is something possible with application domains, but I still did not succeeded...). This means that you will be able to do that only once. Replacing your assembly next time will force you to shut down the service (not really pro...)
  • It is not a good advice to dynamically register and run tasks: from a system administrator's point of view, it sounds like a virus behaviour...

What I should to...

  • Use the ShellExecute task to run your task compiled as a Windows application (worst solution since you loose the "power" of the framework)
  • OR
  • If I understand correctly, you need to create your own client application, then:
    • implement the logic to connect to the autorun server
    • Previously register your task but do not schedule it
    • Then
      • Automatically pilot the schedule (you have to mimic what implement in the screen ScheduleDialog -> Mainly call TaskConfigurationItem.Update())
      • or start manually a task (ScheduleManagement.PlanTask(taskId))
  • OR
  • Schedule your task but implement the triggers in the database so that when a task run, it knows if emails must be sent or not

The last option is the one I usually do: my tasks runs every minute to check if a mail is to be sent: if yes, it sends it, otherwise it exits the process.

It will become more obvious if you download the source code and have a look at the client application.

Hope this helps!

Serge

 

Feb 18, 2010 at 3:21 PM

Hi,

thank you for your quick reply.

what you said below is what I am looking for. In most situations, programmers don't need to use task scheduler directly, we just need to invoke it from our client application. without applications such as AutoRun, we have to create thread for every task (PDF converting, send mails, mesasges-- note that here we talk about tasks, for example, not a single mail, but lots of mails, like a pool or queue), and write logs to see if these tasks failed or not.

I think it is possile to use AutoRun to implement.

1/ using the framwork

2/ write my task (inherited from taskbase)

in my client application, either web or winform ( not in the class library), create mytask instance and set the parameters

3/register my task in the code

4/ schudule it in the code, GUI is not needed.

it seems that you gave the exact solution, just use the ConfigurationManagement, and ScheduleManagement. I think if every class dirived from TaskBase can be registered in the code, everything should work.

  • =========================================
  • If I understand correctly, you need to create your own client application, then:\
    • implement the logic to connect to the autorun server
    • Previously register your task but do not schedule it
    • Then
      • Automatically pilot the schedule (you have to mimic what implement in the screen ScheduleDialog -> Mainly call TaskConfigurationItem.Update())
      • or start manually a task (ScheduleManagement.PlanTask(taskId))
  • OR
  • Schedule your task but implement the triggers in the database so that when a task run, it knows if emails must be sent or not