1

I need my array to automatically clear itself at 2 AM, but at the moment with this code it only clears itself if I manually check it at exactly 2 am. Help appreciated

Datetime todaysDate = DateTime.Now

if (todaysDate.Hour == 02 && todaysDate.Minute == 00)

{
Array.Clear(myArray, 0, myArray.Length);
}
Strayph
  • 13
  • 2
  • Possible duplicate of [C#: How to start a thread at a specific time](https://stackoverflow.com/questions/18611226/c-how-to-start-a-thread-at-a-specific-time) – eocron Mar 02 '18 at 18:55
  • 2
    Instead of using multi-threading or a scheduler for updating an object, consider implementing your own collection and before performing every action (like get, add or remove) check when was last clearing and perform Clear if it's due. – derloopkat Mar 02 '18 at 19:05
  • What about all the values in the array? Lost forever? Red flag for me. – Alexandru Clonțea Mar 02 '18 at 19:33
  • 1
    Possible duplicate of original non-duplicate https://stackoverflow.com/questions/3243348/how-to-call-a-method-daily-at-specific-time-in-c @eocron – Alexandru Clonțea Mar 02 '18 at 19:36

0 Answers0