Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 172689
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T13:12:37+00:00 2026-05-11T13:12:37+00:00

The project I am working on requires some executions to be done at a

  • 0

The project I am working on requires some executions to be done at a certain time. I am not sure what would be the best way to deal with this situation. The method must be able to survive server restart/maintenance. And method calls must be programmatically.

I am considering going down this path:

I could have a table in database (or even a message queue) called TaskTable which could have TaskID(PK), TaskName(varchar), TaskStatus(enum success,failed, scheduled) and TimeOfExecution. But I need a windows service that periodically polls the database for any unexecuted tasks. Problem I am facing is that: What do I use as the TaskName to save into database? Class name? class and method name ToString? And how can I convert the string back and programmatically invoke the method calls (I don’t want to have a giant switch statement)? A typtical task would look like below. So I ned to be able to get the name of the task ‘SendIncompleteNotification’ and class name save it into database and on retrival invoke programatically

public static Task<string> SendIncompleteNotification {   get     {       return new Task<string>         (           a => Console.WriteLine('Sample Task')           , 'This is a sample task which does nothing.'         );    } } 

The problem now is I am having problem saving the method/property name progrmatically.

var type = ApplicationTask.SendIncompleteNotification.GetType(); //type.Name shows 'Task`1' rather than SendIncompleteNotification 

Is there any better ways of dealing with this situation? Thanks!

Updated: Sorry my head was spinning. I now realized what I did wrong was to have another method/property to return my Task. What I should have done was to have a new class inhrite from my Task. And there i can easily get the class name and save the string into db and later retireve back and invoke.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T13:12:38+00:00Added an answer on May 11, 2026 at 1:12 pm

    Is the database a requirement?

    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:

    • A DLL containing the task to execute
    • The name of a class implementing an interface you define
    • Other arguments

    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.

    Edit: example:

    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         }     } } 

    Edit 2: This is in answer to your code sample.

    class YourClass {     public static Task<string> SendIncompleteNotification     {         get {             return new Task<string>(                 s => Console.WriteLine('Executing task... arguments: {0}', s),                 'My task');         }     } }   interface ITask {     void Execute(object o); }  class Task<T> : ITask {             public Task(Action<T> action, string name)     {         Action = action;     }      public string Name { get; set; }     public Action<T> 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();     } } 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.