If you want instant notification when the pitcher expires, you can do the following:
Scan the list of jugs and find the one with the earliest expiration date
Set a timer to expire at that date/time.
When the timer expires, remove that jug from the list.
Scan the list of jugs to find any other jugs that expire at this time.
Send notifications for all the expired jugs.
Go to step 1.
There are several problems with this algorithm:
- If you add a jug, you should check to see if it expires before the current expiration time. If so, you should reset the timer for the current duration of the pitcher.
- , , , , . , reset .
- , , .
, . , . , . , , .
( , , ) . , , . , .
, , . .
, .NET:
TimeSpan expirationDelay = jug.ExpirationDateTime - DateTime.Now;
System.Threading.Timer jugTimer = new System.Threading.Timer(
JugExpirationCallback, null, expirationDelay, TimeSpan.FromMilliseconds(-1));
, , . , Change.
, expirationDelay . , DateTime UTC . WaitableTimer . WaitableTimer .
, , . , , ( ), : . , , , . , , , .
, . , , . , . .
, , : , , . reset .
, " ". , .