.Net定时弹出窗口(c#)
.Net定时弹出窗口(c#)
using System;
using System.Collections;
using System.ComponentModel;
using System.Web;
using System.Web.SessionState;
using System.Threading;
using System.Timers;
namespace PopUp
{
public class Global : System.Web.HttpApplication
{
private System.ComponentModel.IContainer components = null;
private System.Timers.Timer aTimer;
public static DateTime dtBegin;
public static long TimeInterval=10000;
public static bool TimeOut;
public Global()
{
InitializeComponent();
}
protected void Application_Start(Object sender, EventArgs e)
{
TimeOut=false;
dtBegin=DateTime.Now;
aTimer = new System.Timers.Timer();
aTimer.Elapsed+=new ElapsedEventHandler(OnTimedEvent);
aTimer.Interval=TimeInterval;
aTimer.Enabled=true;
}
protected void Session_Start(Object sender, EventArgs e)
{
}
protected void Application_BeginRequest(Object sender, EventArgs e)
{
if (TimeOut==true)
{
TimeSpan ts=DateTime.Now-dtBegin;
string str="<script>alert('You have been in this application ";
str=str+ts.Hours+" hours "+ts.Minutes +" minutes "+ts.Seconds +" seconds!')</script>";
Response.Write(str);
TimeOut=false;
}
}
protected void Application_EndRequest(Object sender, EventArgs e)
{
}
protected void Application_AuthenticateRequest(Object sender, EventArgs e)
{
}
protected void Application_Error(Object sender, EventArgs e)
{
}
protected void Session_End(Object sender, EventArgs e)
{
}
protected void Application_End(Object sender, EventArgs e)
{
this.aTimer.Enabled=false;
}
private void OnTimedEvent(object source, ElapsedEventArgs e)
{
TimeOut=true;
}
#region Web Form Designer generated code
private void InitializeComponent()
{
}
#endregion
}
}