asp.net 定时器

本秂侑毒 提交于 2020-03-20 20:37:28

using System;
using System.Collections.Generic;
using System.Web;
using System.IO;
using System.Web.Security;
using System.Web.SessionState;
using System.Net.Mail;
using System.Configuration;
using CCWOnline.Management.iknow.Web;
using CSI.Management.Model;
using CCWOnline.Management.Web.MyServiceChampion.Interface;
using System.Linq;
using System.Data;

namespace website
{
public class GlobalSuper : System.Web.HttpApplication
{
protected void Application_Start(object sender, EventArgs e)
{
// 在应用程序启动时运行的代码 Create by wuyaunyaun 2014/02/28 星魔力抽奖活动
System.Timers.Timer timer = new System.Timers.Timer(1000);//每秒钟执行以
timer.AutoReset = true;
timer.Enabled = true;
timer.Elapsed += new System.Timers.ElapsedEventHandler(EachDayJob);//使用委托
}

protected void Session_Start(object sender, EventArgs e)
{

}

protected void Application_BeginRequest(object sender, EventArgs e)
{

}

protected void Application_AuthenticateRequest(object sender, EventArgs e)
{

}

protected void Application_Error(object sender, EventArgs e)
{
Exception exception = this.Server.GetLastError();
HttpResponse Response = this.Response;
HttpRequest Request = this.Request;

//发送调试邮件
if (exception != null && ConfigurationManager.AppSettings["DebugerEnable"].ToLower() == "true")
{
if (exception.InnerException != null)
{
SendErrorEmail(exception.InnerException);
}
else
{
SendErrorEmail(exception);
}


//跳转到错误页
// string errorPage = System.Web.Configuration.WebConfigurationManager.AppSettings["ErrorPage"];
// Response.Redirect(errorPage);
}


}

protected void Session_End(object sender, EventArgs e)
{

}

protected void Application_End(object sender, EventArgs e)
{

}

protected void SendErrorEmail(Exception e)
{

}

protected string ParseTemplate(Exception e)
{

}


/// <summary>
/// 定时抽奖事件
/// Create By wuyaunyaun 2014/02/28
/// </summary>
/// <param name="source"></param>
/// <param name="e"></param>
#region
void EachDayJob(object source, System.Timers.ElapsedEventArgs e)//执行的事件
{
    EachDayAward();
}

protected void EachDayAward()//自定义要执行的方法
{

}

 


/// <summary>
/// 获取中奖奖品名称
/// </summary>
/// <param name="Turntable"></param>
/// <returns></returns>
protected string Getname(List<ZhiWeiClass> Turntable)
{
   return LuckDrow(Turntable).ZhiWei;
}

/// <summary>
/// 计算概率
/// </summary>
/// <param name="Turntable"></param>
/// <returns></returns>
private ZhiWeiClass LuckDrow(List<ZhiWeiClass> Turntable)
{
Random Rnd = new Random();
return (from x in Enumerable.Range(0, 1000000) //最多支100万次骰子
let ZhiWeiClass = Turntable[Rnd.Next(Turntable.Count())]
let Sieve = Rnd.Next(0, 100)
where Sieve < ZhiWeiClass.Chance
select ZhiWeiClass).First();
}
#endregion

}
}

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!