Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Is the database a requirement?</p> <p>If not, what about a Windows Scheduled Task (they have a tendancy to "just work") which calls into a general console app. The arguments to the console app could be:</p> <ul> <li>A DLL containing the task to execute</li> <li>The name of a class implementing an interface you define</li> <li>Other arguments</li> </ul> <p>This way you can put all of your tasks into one assembly, or multiple. Alternatively you could create an attribute, apply that attribute to your tasks to give them a "friendly name", and use reflection over the assembly to find classes with the matching attribute. </p> <p>Edit: example:</p> <pre><code>interface ITask { void Execute(ExcecutionContext context); } [TaskName("Send Emails") class SendEmailsTask : ITask { public void Execute(ExcecutionContext context) { // Send emails. ExecutionContext might contain a dictionary of // key/value pairs for additional arguments needed for your task. } } class TaskExecuter { public void ExecuteTask(string name) { // "name" comes from the database entry var types = Assembly.GetExecutingAssembly().GetTypes(); foreach (var type in types) { // Check type.GetCustomAttributes for the TaskAttribute, then check the name } } } </code></pre> <p>Edit 2: This is in answer to your code sample.</p> <pre><code>class YourClass { public static Task&lt;string&gt; SendIncompleteNotification { get { return new Task&lt;string&gt;( s =&gt; Console.WriteLine("Executing task... arguments: {0}", s), "My task"); } } } interface ITask { void Execute(object o); } class Task&lt;T&gt; : ITask { public Task(Action&lt;T&gt; action, string name) { Action = action; } public string Name { get; set; } public Action&lt;T&gt; Action { get; set; } void ITask.Execute(object o) { Action((T)o); } } class Program { static void Main(string[] args) { // Assume that this is what is stored in the database var typeName = typeof (YourClass).FullName; var propertyName = "SendIncompleteNotification"; var arguments = "some arguments"; // Execute the task var type = Type.GetType(typeName); var property = type.GetProperty(propertyName); var task = (ITask)property.GetValue(null, null); task.Execute(arguments); Console.ReadKey(); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload