英文:
How to make jobs running offline on my game app?
问题
我正在开发一个简单的游戏,面临了我从未研究过的情况。游戏中有一些选项和情况,例如建设、农耕等,会在开始后的几小时或几分钟内完成,例如,我已经开始了我的家庭建设,它将在现实生活中花费3小时。我们假设在3小时后,我的应用程序必须运行一个函数来完成并更新数据库。
我该如何做呢?我真的不知道。我已经阅读了很多文章,但我不知道对我的情况来说什么是正确的操作。
我正在使用Angular制作我的前端,使用.netcore c#制作后端。
英文:
I am developing a simple game and i faced a situation i have never studied about.
Inside the game there are options and situations that something such as a construction, farming, will be finished some hours or minutes after starting, for example, i've started my home construction and it will take 3 hours on real life. We assume that 3 hours after it my application must run a function to finish that and update database.
How can i make this? I really don't know. I have read a lot of articles but i don't know what is the correct action for my situation.
I am making my frontend using Angular and backend using .netcore c#
答案1
得分: 1
有很多方法可以实现这个。你可以,例如:
- 将建筑完成的时间写入数据库表中。
- 当用户下次打开游戏时,查找所有已完成的建筑,并标记它们为完成状态。然后就不需要后台处理了。
或者,如你所提议的:
- 每分钟运行一个后台作业,查找数据库中所有用户的刚刚完成的建筑并标记为完成状态。
这看起来是最新的(截止至撰写时)做法:ASP.NET托管服务。但如果你搜索“asp.net后台任务”,还有很多其他方法。
英文:
There's lots of ways you could do this. You could e.g.
- write into a database table the time when the construction will complete
- when the user next opens the game, look for all of their constructions that have completed and mark them complete. Then you don't need any background processing.
or, as you propose,
-
run a background job every minute to look for constructions that have just completed for all users in the database and mark completed.
This looks like the latest (at time of writing) way of doing this: ASP.NET Hosted Services. But if you search for "asp.net background tasks" there are plenty of other ways.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论