goofyui
goofyui

Reputation: 3492

How to refresh the app database silently?

In my code logic I have 30 min time expiration condition. When the current time is equal to time activated + 30 min, the activation will get expired. Internally in the SQLite, I need to update IsActive flag = 0.

How to refresh the app database silently?

Upvotes: 0

Views: 68

Answers (1)

xleon
xleon

Reputation: 6365

You don´t even need to update a flag. You just need a date field in your database.

Assuming you are using an ORM like sqlite-net-pcl or similar:

YourEntity.ActivationDate = DateTime.Now;
// save your entity

Later on:

var entity = // get the entity from database
var isActivated = DateTime.Now < entity.ActivationDate.AddMinutes(30);

The very same code that checks for activation could update the flag:

var entity = // get the entity from database
if(entity.IsActive && DateTime.Now > entity.ActivationDate.AddMinutes(30))
{
    entity.IsActive = false;
    // save entity to db table
}

This way you avoid implementing background services.

Upvotes: 1

Related Questions