发邮件代码已实现,现求怎样才能激活发邮件的代码,请各位大虾帮忙!

解决方案 »

  1.   

    利用一个守护线程,这个线程在程序入口创建.
    给你一个例子看一下:
    public class ScheduleService : System.Web.UI.Page
    {
    public static ScheduleService inst;
    public static Thread oThread;
    protected Database data;
    protected log4net.ILog log;
    private ScheduleService()
    {
    data=new Database();
    log=log4net.LogManager.GetLogger("Logging");
    if(oThread!=null) oThread.Abort();
    oThread = new Thread(new ThreadStart(CheckStatus));
    oThread.Name=System.Guid.NewGuid().ToString();
    oThread.Start();
    }
    public static ScheduleService getInstance(){
    if(inst==null) inst=new ScheduleService();
    return inst;
    }
    //************<程序入口调下面这个函数就OK了>****************
    public static void statrSchedule()
                      {
    getInstance();
    }
    public void CheckStatus(){

    while(true){
    try
    {
    checkInfo();
    }
    catch(Exception e)
    {
    log.Info(e.ToString());
    }
    finally{

    }
    Thread.Sleep(1000);
    }
    } void checkInfo()
    {
                            //在这里写发邮件的代码.
    }
    }