《拓文asp.net网站内容管理系统》官方演示站。
 设为首页  
 收藏本站
 作者:黄振安
 QQ:53854651
首 页 开源拓文.NET编程网站编程网页设计图形图像数据库软件工程留言本
    站内搜索:  
您现在的位置: 拓文网络 → .NET编程 → ASP.NET → ASP.NET实现用户在线检测的类源码[正文]

热 门 文 章

相 关 文 章
  • ASP.NET性能优化
  • 在.NET框架应用程序中发送电子邮件
  • .net打包自动安装数据库
  • asp.net开发wap必备:更好的匹配手机设备
  • 用ashx动态生成文件
  • windows 2003下asp.Net站点无法使用用户名+密码的方
  • ASP.NET中17种正则表达式
  • 提高ASP.Net应用程序性能的十大方法
  • 一个通过web.Mail发送邮件的类
  • 在DataGrid里面根据日期的不同显示new图标
  • ASP.NET实现用户在线检测的类源码
     
    [作者:不详    转贴自:不详    点击数:    更新时间:2006-3-17 20:33:12]


            
            /*
            下面开始建立守护线程类:
            (注:此处,开始写的时候本来想做成单件模式的,不过由于以前没有做过这个东西,所以反而发生
            了很多问题,最后决定放弃而使用现有的格式)
            */
            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;
                              this.thread  =  new  Thread(new  ThreadStart(ThreadProc))  ;
                              thread.Name  =  "online  user"  ;
                              thread.Start()  ;
                            }
                    }
        
        
                    internal  void  ThreadProc()
                    {
                            while(true)    
                            {
    //                            SohoProject.OnLineUser  temp=new  SohoProject.OnLineUser();    //定义一个用户对象
    //            for  (int  i=0  ;i<  temp.alluser.Count;i++)
    //                    {
    //                      User  tmpuser=(User)temp.alluser[i];
    //                      //我是将该用户的最新时间加上30秒,然后和当前时间比较,小与当前时间,
    //                      //则表示该用户已经吊线,则删除他的记录
    //                      if(tmpuser.curtime.AddSeconds(DELAY_SECONDS).CompareTo(DateTime.Now)<0)  
    //                      {
    //                        temp.alluser.RemoveAt(i);
    //                      }
    //                    }

            

            SohoProject.OnLineUser  temp=new  SohoProject.OnLineUser();    //定义一个用户对象
            //开始检查是否有用户过期了        string  strExpr;
            //tmpuser.curtime.AddSeconds(DELAY_SECONDS).CompareTo(DateTime.Now)<0
            strExpr  =  "curtime  <  '"  +  DateTime.Now.AddSeconds(  0  -  DELAY_SECONDS)  +  "'";  
    #if  DEBUG
            (new  SohoProject.SohoDebug()).WriteToDoc(strExpr);
    #endif

            DataRow[]  curUser;
            //  Use  the  Select  method  to  find  all  rows  matching  the  filter.
            curUser  =  temp.alluser.Select(strExpr);

            if  (curUser.Length  >0  )
            {
              //删除这些记录
              for(int  i  =  0;  i  <  curUser.Length;  i  ++)
              {
                curUser[i].Delete();
              }
              temp.alluser.AcceptChanges();
            }
                                    Thread.Sleep(DELAY_TIMES)  ;
                            }
                    }
            }
    }
    首页 | 1 | 2 | 3 | 4 | 5 | 尾页  共 5 页
     
    winner 打印本页 关闭窗口

         文 章 评 论
    评论人 查看该文章的评论 发表时间
       笔 名* : 0 50分 60分 70分 80分 90分 100分
    评论内容 *: (最多1000字。当前字数:0)


    80 分丰富fffffff2006-4-6 23:50:33

    - 关于本站 - 网站帮助 - 下载声明 - 友情连接 - 网站地图 -
    Copyright © 2005-2006 myTopWin.Com. All Rights Reserved . [桂ICP备06004496号]