I would like to set property for a X minutes. After that period it should return null or expired.
Is there any simple mechanism in C#?
Like this:
private static TimeCache<LoginData> _session;
private void Login() {
...
_session.Set(ws.Login());
}
private void DoStuff() {
if (_session.Expired)
Login()
...
}
2
Answers
You can use a Timer event
OnTimedEvent
to reset your property, but be mindful about the thread safety of your property.You can create a simple class for this.
To use it, you could do something this: