打印本文 打印本文 关闭窗口 关闭窗口
ASP.NET实现用户在线检测的类源码
作者:武汉SEO闵涛  文章来源:敏韬网  点击数2678  更新时间:2009/4/23 10:45:56  文章录入:mintao  责任编辑:mintao
p; ;  i  ++)
                    {
                      //循环判断用户是否已经存在                      SohoProject.User  tempuser  =  (SohoProject.User)_alluser[i]  ;

                      if(  tempuser.sessionid.Equals(user.sessionid))
                      {
            //更新用户在线时间
            tempuser.name=user.name;
            tempuser.curtime=DateTime.Now;
            tempuser.iswhere=user.iswhere;
            tempuser.sessionid=user.sessionid;
            tempuser.ip=user.ip;
            alluser[i]=tempuser;
            return(true);
            //return(true);  //用户已经存在,则直接退出                      }
                  }
                    _alluser.Add(user);
                    return  (true);
                  }
                }    
                
                //功能说明:判断某用户是否在线,本部分暂时不用
    //返回值:TRUE代表在线,FALSE不在
                public    Boolean  IsUserOnLine(string  name)
                {
                  //需要先判断用户是否已经在用户列表中了
                  if(_alluser==null)
                  {
                    return  (false);
                  }
                  else
                  {
                    for  (  int  i  =  0  ;  i  <  _alluser.Count  ;  i  ++)
                    {
                      //循环判断用户是否已经存在                      SohoProject.User  tempuser  =  (SohoProject.User)_alluser[i]  ;
                      if(tempuser.name.ToLower().Equals(name.ToLower()))
                      {
                        return(true)  ;
                      }
                  }
                    return  (false);
                  }
                }
                
                //功能说明:更新用户在线时间
    //返回值:最新的在线用户列表
                public  Boolean  CheckUserOnLine(string  name,string  iswhere,string  sessionid,string  ip)
                {
                  //需要先判断用户是否已经在用户列表中了
                  if(_alluser!=null)
                  {
                    User  newuser=new  User();
        newuser.name=  name;
        newuser.iswhere=  iswhere;
        newuser.lasttime=newuser.curtime=DateTime.Now;
        newuser.sessionid=sessionid;
        newuser.ip=ip;
        
        //OnLineUser  alluser=  new  OnLineUser();
        AddUserToOnLine(newuser);
      }
      return(false);
                }
        }
        
        
        
        /*
        下面开始建立守护线程类:
        (注:此处,开始写的时候本来想做成单件模式的,不过由于以前没有做过这个东西,所以反而发生
        了很多问题,最后决定放弃而使用现有的格式)
        */
        public  class  CheckOnline  
        {
          const  int  DELAY_TIMES  =  10000  ;        //定义执行的时间间隔为5秒
          const  int  DELAY_SECONDS=60;          //将用户掉线时间设置为30秒
          
    private  Thread  thread  ;            //定义内部线程
    private  static  bool  _flag=false;      //定义唯一标志
    
    public  CheckOnline()
    {
                  if  (!_flag)
                  {
                    _flag=  true;
             

上一页  [1] [2] [3] [4]  下一页

打印本文 打印本文 关闭窗口 关闭窗口