











在cnblogs博问中回答问题http://space.cnblogs.com/q/15717/,特做了个小例子,希望能够帮助新手朋友们扩宽思路
Default.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
当前临时列表中有 <%=计数器.计数器实例.临时保存访问列表.Count %> 条记录等待着往数据库里插。
</div>
</form>
</body>
</html>
Default.aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
计数器.计数器实例.临时保存访问列表.Add(Request.UserHostAddress);
}
}
计数器.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Threading;
using System.Diagnostics;/// <summary>
///计数器 的摘要说明
/// </summary>
public class 计数器
{
public static readonly 计数器 计数器实例 = new 计数器();/// <summary>
/// 用来临时保存访问者的IP列表
/// </summary>
public List<string> 临时保存访问列表;private 计数器()
{
临时保存访问列表 = new List<string>();
Thread 数据插入线程
= new Thread( 数据插入线程.Start();
}
}
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。