-1

I'm following the documentation and other SO posts, but I'm getting the error:

No overload for RecordKeeper matches delegate ElapsedEventHandler

for the following code.

        ...
        System.Timers.Timer aTimer = new System.Timers.Timer();
        aTimer.Elapsed += Server.RecordKeeper;
        aTimer.Interval = 5000;
        aTimer.Enabled = true;
        ...


        public void RecordKeeper(object sender, ElapsedEventHandler e)
    {
        for (int x = 0; x < record_list.Count; x++)
        {
            record_list[x].TTL = record_list[x].TTL.Add(TimeSpan.FromSeconds(1));
            Console.WriteLine(record_list[x].TTL.ToString());
            if (record_list[x].TTL > TimeSpan.FromSeconds(70))
            {
                RemoveRecord(x);
            }
        }                          
    }

I seem to be doing this exactly as other examples found in This post.

Thanks in advance for any help.

Community
  • 1
  • 1
MrDysprosium
  • 489
  • 9
  • 20
  • 1
    You have the wrong definition for the `RecordKeeper` method. The second parameter needs to be of type `System.Timers.ElapsedEventArgs` – DavidG Oct 06 '16 at 14:23
  • A TTL should be a fixed value _(this might be saved in the record, but could be from a config)_. I would suggest to add a `CreationDateTime` field and compare it like `record_list[x].CreationDateTime.Add(record_list[x].TTL) < DateTime.Now` _(or UtcNow)_ This way you never need to modify the record. **AND** the timing is more accurate. A timer is never accurate... – Jeroen van Langen Oct 06 '16 at 14:37
  • @JeroenvanLangen Wow, thank you for that! Although, I do need to reset the TTL timer if it receives an update. Each record needs to receive an update at least once a minute to be considered "alive". – MrDysprosium Oct 06 '16 at 14:38

1 Answers1

1

Try with:

public void RecordKeeper(object sender, ElapsedEventArgs e)
{
    for (int x = 0; x < record_list.Count; x++)
    {
        record_list[x].TTL = record_list[x].TTL.Add(TimeSpan.FromSeconds(1));
        Console.WriteLine(record_list[x].TTL.ToString());
        if (record_list[x].TTL > TimeSpan.FromSeconds(70))
        {
            RemoveRecord(x);
        }
    }                          
}

Your function signature for RecordKeeper is not correct.

Thomas K
  • 64
  • 1
  • 7