1 public class Global : System.Web.HttpApplication
2 {
3 //只处理静态的数据
4 //只调用一次,
5 //HttpFactory.Init 之后,有EnsureAppStart
6
7 //public static int OnLineNum = 0;
8
9 void Application_Start(object sender, EventArgs e)
10 {
11 // 在应用程序启动时运行的代码
12 Application.Lock();
13
14 //Monitor.Enter();
15 Application["online"] = 0;
16 Application.UnLock();
17 }
18
19 void Application_End(object sender, EventArgs e)
20 {
21 // 在应用程序关闭时运行的代码
22
23 }
24
25 void Application_Error(object sender, EventArgs e)
26 {
27 // 在出现未处理的错误时运行的代码
28
29 }
30
31 void Session_Start(object sender, EventArgs e)
32 {
33 // 在新会话启动时运行的代码
34 this.Response.Write("session start <br />" + Application["online"]);
35
36 Application.Lock();
37
38 Application["online"] = int.Parse(Application["online"].ToString()) +1;
39
40 Application.UnLock();
41
42 }
43
44 void Session_End(object sender, EventArgs e)
45 {
46 // 在会话结束时运行的代码。
47 // 注意: 只有在 Web.config 文件中的 sessionstate 模式设置为
48 // InProc 时,才会引发 Session_End 事件。如果会话模式设置为 StateServer
49 // 或 SQLServer,则不会引发该事件。
50
51 Application.Lock();
52
53 Application["online"] =Math.Max((int.Parse(Application["online"].ToString())-1),0);
54
55 Application.UnLock();
56
57 }
58
59 }