1. 创建一个class library项目 (把xxx替换成你自己的实际名字)
Demo code:


using System;
using System.Collections.Generic;
using System.Text;
using DotNetNuke.Services.Scheduling;
using DotNetNuke.Services.Exceptions;
using System.Net;
using System.IO;
namespace Com.xxx.KeepAlive
{
public class KeepAlive : SchedulerClient
{
//REQUIRED
public KeepAlive(ScheduleHistoryItem objScheduleHistoryItem)
{
this.ScheduleHistoryItem = objScheduleHistoryItem;
}
public override void DoWork()
{
HttpWebResponse webRes = null;
Stream objStream = null;
StreamReader objStreamReader = null;
try
{
webRes = (HttpWebResponse)WebRequest.Create("http://www.xxx.cn/KeepAlive.aspx").GetResponse();
objStream = webRes.GetResponseStream();
objStreamReader = new StreamReader(objStream, Encoding.Default);
string content = objStreamReader.ReadToEnd();
//Optional
base.ScheduleHistoryItem.AddLogNote(content + " -- " + DateTime.Now);
//objStreamReader.Close();
//objStream.Close();
//webRes.Close();
//REQUIRED
base.ScheduleHistoryItem.Succeeded = true;
}
catch (Exception exce)
{
//REQUIRED
base.ScheduleHistoryItem.Succeeded = false;
base.Errored(ref exce);
//Optional
DotNetNuke.Services.Exceptions.Exceptions.LogException(exce);
}
finally
{
if (objStreamReader != null)
{
objStreamReader.Close();
}
if (objStream != null)
{
objStream.Close();
}
if (webRes != null) { webRes.Close(); }
}
}
}
}
之后,编译成dll,并放到dnn的bin目录下
2. DNN里面的Schedule配置。
用host用户登陆后,到Host->Schedule里面,点击“Add new item to Schedule”
如下图:
需要注意的就是:Full class Name and Assembly。
比如本例的Full class Name 就是:Com.xxx.KeepAlive.KeepAlive,
Assembly的Name就是Com.xxx.KeepAlive (这个名字是我自己取的,你可以在项目-》右键属性中修改和查看。)
ok,my story is over.