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

  • SEARCH
  • Home
  • 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 3432674
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T07:28:44+00:00 2026-05-18T07:28:44+00:00

This question has probably already been answered somewhere but I’m having a hard time

  • 0

This question has probably already been answered somewhere but I’m having a hard time formulating it correctly which makes it hard finding anything about it.

Let’s say I have items in my WinForms application which have an expiration date. I have more different conditions than this one but let’s do it simple. I’d like to trigger an event when an item comes to expiration. What is the ideal way to do so? Checking every X minutes? I’m confused as if this is the best solution.

code samples in both VB.net or C# are welcome.

Thank you

  • 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. Editorial Team
    Editorial Team
    2026-05-18T07:28:45+00:00Added an answer on May 18, 2026 at 7:28 am

    Use either the SortedDictionary like CodeInChaos mentioned, or a SortedList. Choose which one based on the “Remarks” section for each. Both have O(log n) retrieval since they’re implemented as a binary search tree (that I assume is somehow balanced). Both will be marginally faster in specific circumstances described in their documentation.

    Basically the idea is to maintain two data structures:

    1. Your collection of items

    2. A sorted collection of references to the items sorted by their expiration date.

    You need some sort of Update() loop that will just look at the first index of the Values property of your SortedList or SortedDictionary (O(1) operation) and see if the system date is past that item’s expiration date.

    Here’s simple usage with just strings and ints:

    using System;
    using System.Collections.Generic;
    using System.Text;
    
    namespace TestDataStructures
    {
        class Program
        {
            static void Main(string[] args)
            {
                SortedList<int, string> dict = new SortedList<int, string>();
                for (int i = 42; i < 100; i++) {
                    dict.Add(i, i.ToString());
                }
                for (int i = 41; i > 0; i--) {
                    dict.Add(i, i.ToString());
                }
    
                Console.Out.WriteLine("Smallest value is " + dict.Values[0]);
                Console.ReadKey();
            }
        }
    }
    

    Whenever you add a new item to your main collection, add a reference to it in this SortedList/SortedDictionary and provide the expiration date as the key to sort by. Storing the references requires a little more memory overhead, but like CodeInChaos said, it will be much faster. I don’t think it’s terribly difficult to code though.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Preamble So, this question has already been answered, but as it was my first
I suspect this has already been answered somewhere, but I can't find it, so...
I know this question has probably been asked already but I would really like
I feel like this question has probably been asked a thousand times already, so
This is probably a silly question, but curiosity has gotten the better of me.
I fear this is probably a bit of a dummy question, but it has
This question has been asked before ( link ) but I have slightly different
If this question has already been asked I appologies, please point me in the
I know this question has been asked before, but I ran into a problem.
I know this question has been asked a bit before. But looking around I

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.