如何每1分钟检查一次用户状态 [英] How to check user status every 1 minute

查看:97
本文介绍了如何每1分钟检查一次用户状态的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用ASP.NET建立网站.这是一个游戏,我随机地将两个用户连接在一起,彼此玩.

我需要做的是,当这两个玩家之一退出游戏或在一段时间内不活跃时,我结束了游戏并将另一个玩家发送到某个页面以告诉他或她游戏结束了.

我的问题是我无法弄清楚如何每次都跟踪用户状态.我知道ASP.NET具有(LastActivityDate),但是例如如何每30秒重复检查一次此值?

I''m building a website using ASP.NET. It''s a game which I connect two users randomly to play with each other.

What I need to do is when one of these two players logs out or has been inactive for a certain time, I finish the game and send the other player to some page to tell him or her the game is over.

My problem is I can''t figure out how to track the user status every while. I know that ASP.NET has (LastActivityDate), but how can I check this value repeatedly every 30 seconds for example?

推荐答案

使用AJAX.编写一个简单的javascript函数,以对Web应用程序上的处理程序进行AJAX调用,并发送一些用户ID.在该处理程序中,使用id标记用户为活动状态并检查对手的状态.
Use AJAX. Write a simple javascript function to make an AJAX call to a handler on your web app, sending some user id. In that handler use the id to mark user active and check the opponents status.


使用^ ]对象.
会话状态事件 [
Use session[^] object.
Session-state events[^]


这篇关于如何每1分钟检查一次用户状态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆