5

I have access only to .NET, and I have this situation. At creating an game (or any object for that matter), I set expiration date (or any date, that's not really important). Date is set at some point in future. Now What I want to do is to check if that date occurred. And this should happen completely automatically. Without user interactions.

My question is.. ? Is that possible? And where to start?

EDIT:

I have date stored in database, and i want to periodically check if that date actually occurred. I guess asking server every second to check date stored in DB is not most optimal solution.

3
  • Needs more detail, what is this for? A client app? A web app? A service? But the long and short is you would have to either have some sort of regularly scheduled thing checking for things that have expired or you'd have to schedule something at the expiry time to disable whatever you want. Commented Jan 14, 2011 at 22:23
  • Are you asking how to set up a background thread that can periodically check a date and take action if it has expired? Commented Jan 14, 2011 at 22:36
  • 1
    catb.org/~esr/faqs/smart-questions.html Commented Jan 14, 2011 at 22:56

2 Answers 2

13

You should be able to just fine...

if(DateTime.Now > expirationDate) { /* TODO:... */ }
2
  • 1
    Shouldn't it be >=? Just sayin'
    – Jess
    Commented Sep 2, 2015 at 20:26
  • How can you set a time to work in different day formats? IE, 03/06/2017 could mean 3rd of June in UK, and 6th of Match in the US.
    – HippoDuck
    Commented Oct 9, 2016 at 20:07
0

Yes, that's possible and I do it all the time as a part time freelancer. But to make the scheme more robust you can use Windows registry. You compute hash code of your app and serialize you user object together with expiration date value.

    [Serializable]
public class DateChecker
{

    public string HashCode { get; set; }

    public DateTime ExpirationDate { get; set; }

}

Then you check against registry and see if data has been tampere with. This is also stable to user's changing computer date to some past. Works 100%.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.