OnlineUserList.Add(CurrentUser);//用户登录成功后添加public List<UserData> GetonlineUsers()//写一个方法用于返回已经登录了的所有用户 { return OnlineUserList; }其次是在页面中定时更新UserLastTime字段的值:
dispatcherTimer Timer = new dispatcherTimer();Timer.Interval = new TimeSpan(5000);Timer.Tick += new EventHandler(Timer_Tick);Timer.Start();voID Timer_Tick(object sender,EventArgs e) { IProxy mproxy = Factory.Service; mproxy.SetUserLastTime(CurrentUser,result => { }); } public string SetUserLastTime(UserData ud) { if (ud != null) { for (int i = 0; i < OnlineUserList.Count; i++) { if (OnlineUserList[i].ID == ud.ID) { OnlineUserList[i].UserLastTime=DateTime.Now; } } } return ""; }
最后是如果UserLastTime字段的值跟当前系统时间相差二十秒的话就将当前用户从List<UserData>中移除:
voID Current_Exit(object sender,EventArgs e) { <pre name="code" > IProxy mproxy = Factory.Service;mproxy.OfflineUser(CurrentUser,result => { });
}
public string OfflineUser(UserData ud) { if (ud != null) { for (int i = 0; i < OnlineUserList.Count; i++) { if (OnlineUserList[i].ID== ud.ID) { OnlineUserList.Remove(OnlineUserList[i]); } } } return ""; }dispatcherTimer timer = new dispatcherTimer();timer.Interval = new TimeSpan(3000);timer.Tick += new EventHandler(timer_Tick);timer.Start();
voID timer_Tick(object sender,EventArgs e) { foreach (UserData ud in OnlineUsers) { DateTime cn = new DateTime(); cn = DateTime.Now; if (ud.UserLastTime.AddSeconds(20) < cn) { UserData ud1 = new UserData(); ud1.ID = ud.ID; ud1.name = ou.name; IProxy _proxy = Factory.Service; _proxy.OfflineUser(ud1,result => { }); } }<pre name="code" ><pre name="code" > }总结
以上是内存溢出为你收集整理的Silverlight中用户直接退出浏览器时如何判断用户离线全部内容,希望文章能够帮你解决Silverlight中用户直接退出浏览器时如何判断用户离线所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)