C# 如何以静默方式刷新应用程序数据库?
在我的代码逻辑中,我有30分钟的时间到期条件。当当前时间等于激活时间+30分钟时,激活将过期。在SQLite内部,我需要更新IsActive flag=0C# 如何以静默方式刷新应用程序数据库?,c#,sqlite,xamarin,xamarin.forms,C#,Sqlite,Xamarin,Xamarin.forms,在我的代码逻辑中,我有30分钟的时间到期条件。当当前时间等于激活时间+30分钟时,激活将过期。在SQLite内部,我需要更新IsActive flag=0 如何以静默方式刷新应用程序数据库?您甚至不需要更新标志。您只需要在数据库中输入一个日期字段 假设您正在使用类似ORM或类似ORM: YourEntity.ActivationDate = DateTime.Now; // save your entity 稍后: var entity = // get the entity from dat
如何以静默方式刷新应用程序数据库?您甚至不需要更新标志。您只需要在数据库中输入一个日期字段 假设您正在使用类似ORM或类似ORM:
YourEntity.ActivationDate = DateTime.Now;
// save your entity
稍后:
var entity = // get the entity from database
var isActivated = DateTime.Now < entity.ActivationDate.AddMinutes(30);
这样可以避免实现后台服务。您需要在每个操作系统中使用后台服务来实现。它是否在事件中?何时检查过期条件?在发布、简历或其他地方?如果您进行了检查,并且满足了条件,则启动sql查询并根据需要设置标志。这里到底是什么问题?我实现了提到日期时间的相同逻辑。现在>=激活日期时间。。它工作得很好。。谢谢
var entity = // get the entity from database
if(entity.IsActive && DateTime.Now > entity.ActivationDate.AddMinutes(30))
{
entity.IsActive = false;
// save entity to db table
}