You can start a background thread with the following statement:
Checkonline online=new checkonline ();
The user can put it to global. asax, I did not, just put in an ASPX file to do a simple test. As follows
Start.aspx
<%@ page language= "C #" Autoeventwireup=true debug= "true"%>
<%@ Assembly name= "Soholife"%>
<% @Import namespace= "System"%>
<% @Import namespace= "Soholife"%>
<% @Import namespace= "System.Collections"%>
<script runat= "Server" language= "C #" >
void Page_Load (Object sender, EventArgs args)
{
Checkonline online=new checkonline ();
}
</script>
<style type= "Text/css" >
Td{font-size:12;}
. Bgcolor{background: #ffffcc;}
</style>
<body><center>
</center></body>
And we also need a program to display the data currently supported online, the program is as follows:
Online.aspx
<%@ page language= "C #" Autoeventwireup=true debug= "true"%>
<%@ Assembly name= "Soholife"%>
<% @Import namespace= "System"%>
<% @Import namespace= "Soholife"%>
<% @Import namespace= "System.Collections"%>
<script runat= "Server" language= "C #" >
void Page_Load (Object sender, EventArgs args)
{
Onlineuser temp= new Onlineuser ();
ArrayList AllUser =temp.alluser;
String Str= "";
str + = "<tr bgcolor= #ffff99 >";
str + = "<TD width=100 align=center class=" CoolBar "> Users </td>";
str + = "<TD align=center width=150 class=" CoolBar "> Login time </td>";
str + = "<TD align=center width=150 class=" CoolBar "> Recent time </td>";
str + = "<TD width=100 height=20 class=" CoolBar "> Current position </td>";
str + = "</tr>";
for (int i = 0; i < AllUser. Count; i++)
{
Soholife.user tempuser= (Soholife.user) alluser[i];
str + = "<tr bgcolor=white>";
str + = "<td>" + tempuser.name + "</td>";
str + = "<td>" + tempuser.lasttime + "</td>";
str + = "<td>" + tempuser.curtime + "</td>";
str + = "<Td>" + tempuser.iswhere + "</td>";
str + = "</tr>";
}
MainInfo. TEXT=STR;
}
</script>
<style type= "Text/css" >
Td{font-size:12;}
. Bgcolor{background: #ffffcc;}
</style>
<script language=javascript>
function Openwindow (url,w,h)
{
window.open (URL, "", "toolbar=no,menubar=no,directories=no,status=yes,width=" + W + ", height=" + H + ", Scrollbars=yes, Resizable=yes ");
return false;
}
</script>
<body bgcolor= "#ccffcc" ><center>
<Br>
<table width=450 bgcolor=white cellpadding= "0" cellspacing= "0" style= "Border:none";>
<TR><TD colspan=2 align=center class= "Bar" > Current online users </td></tr>
</table><br>
<asp:label font-size= "8pt" id= "showmsg" runat= "Server"/>
<table width=450 bgcolor=white cellpadding= "2" cellspacing= "1" class= "Grid" >
<asp:label font-size= "8pt" id= "MainInfo" runat= "Server"/>
</table>
</center></body>
Online user detection in ASPNET (using background daemon threads)