none
create hundreds of tasks with minimal overhead RRS feed

  • Question

  • How to create hundreds of tasks with minimal overhead. Let us consider that in my application that i have thousands of users registered for their birthday reminders. I need to write a scheduler task each registered which wakes up before birthday and greet them.

    1 .How to do this?
    2. believe TPL has support for handling this sceneraio and some link to real world examples (avoid hello world style applications)

    TIA, Holy
    • Edited by Holysmoke Tuesday, May 5, 2015 8:23 PM
    Tuesday, May 5, 2015 8:23 PM

Answers

  • I don't see what TPL has to with the problem, are you planning to use Task.Delay to wait until a user birthday occurs? That's overkill.

    All you need is a suitable data structure to store those birthday dates and some code which checks that data every day to see find the current birthdays.

    That data structure could be a SortedDictionary<Key, Value> where the key is BirthdayDate object which stores the month and day of the birthday (you could also use DateTime if you're a bit careful with the year part) and the value is a list of persons those birthdays occur on that date.

    Checking the data structure every day can be done by using any suitable .NET timer class if the application is always running. If not, you'll probably want to use the Windows Task Scheduler to start the application every day.

    • Proposed as answer by Fred BaoModerator Wednesday, May 6, 2015 1:27 AM
    • Marked as answer by Holysmoke Wednesday, May 6, 2015 8:20 AM
    Tuesday, May 5, 2015 9:12 PM
    Moderator