做一个windows服务,这个服务用来定时访问一个网站[转贴]
2005-04-26 12:57
471 查看
1、新建一个"Windows服务"项目
2、然后在工具箱中“组件”栏拖一个"Timer"下来
3、双击自动产生下列事件:
private void timer1_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
{
//这里编写自动访问网站代码
System.Net.WebClient wc=new System.Net.WebClient();
wc.DownloadData("http://www.csdn.net");
}
2、在自动产生的Service1.cs文件中找到
protected override void OnStart(string[] args)
{
// TODO: 在此处添加代码以启动服务。
//这里启动和设置Timer
timer1.Interval = 10000;//毫秒
timer1.Start();
}
funy:
PageUrl1 = "http://www.csdn.net";
WebRequest request1 = WebRequest.Create(PageUrl1);
WebResponse response1 = request1.GetResponse();
Stream resStream1 = response1.GetResponseStream();
StreamReader sr1 = new StreamReader(resStream1, System.Text.Encoding.GetEncoding("GB2312"));
indexhtml1 = sr1.ReadToEnd();
resStream1.Close();
sr1.Close();
string templatefile1;
templatefile1 = @"d:/index.htm";
StreamWriter sw1 = new StreamWriter(templatefile1,false,System.Text.Encoding.GetEncoding("GB2312"));
sw1.Write(indexhtml1);
sw1.Close();
把逻辑功能代码改成我上面写的就实现对页面的访问了吧,而且还把页面的源代码存入了一个html
我是拿这个做成了一个服务,每一分钟做一次,目的是提高网站的访问速度,:)
2、然后在工具箱中“组件”栏拖一个"Timer"下来
3、双击自动产生下列事件:
private void timer1_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
{
//这里编写自动访问网站代码
System.Net.WebClient wc=new System.Net.WebClient();
wc.DownloadData("http://www.csdn.net");
}
2、在自动产生的Service1.cs文件中找到
protected override void OnStart(string[] args)
{
// TODO: 在此处添加代码以启动服务。
//这里启动和设置Timer
timer1.Interval = 10000;//毫秒
timer1.Start();
}
funy:
PageUrl1 = "http://www.csdn.net";
WebRequest request1 = WebRequest.Create(PageUrl1);
WebResponse response1 = request1.GetResponse();
Stream resStream1 = response1.GetResponseStream();
StreamReader sr1 = new StreamReader(resStream1, System.Text.Encoding.GetEncoding("GB2312"));
indexhtml1 = sr1.ReadToEnd();
resStream1.Close();
sr1.Close();
string templatefile1;
templatefile1 = @"d:/index.htm";
StreamWriter sw1 = new StreamWriter(templatefile1,false,System.Text.Encoding.GetEncoding("GB2312"));
sw1.Write(indexhtml1);
sw1.Close();
把逻辑功能代码改成我上面写的就实现对页面的访问了吧,而且还把页面的源代码存入了一个html
我是拿这个做成了一个服务,每一分钟做一次,目的是提高网站的访问速度,:)
相关文章推荐
- 一个Windows后台服务(.Net的C#版) - 定时访问数据库循环发送手机短信
- 一个Windows后台服务(.Net的C#版) - 定时访问数据库循环发送手机短信
- 转载 : 一个Windows后台服务(.Net的C#版) - 定时访问数据库循环发送手机短信
- 一个Windows后台服务(.Net的C#版) - 定时访问数据库循环发送手机短信
- 一个Windows后台服务(.Net的C#版) - 定时访问数据库循环发送手机短信
- 一个Windows后台服务(.Net的C#版) - 定时访问数据库循环发送手机短信
- 一个定时网络唤醒的Windows 2000服务(Service)程序
- 2008年3月小记(设置Windows服务的依赖关系,配置MSMQ的访问权限,WCF的安全配置,删除重建网站,HttpWebRequest,一年中的周,在WCF中使用HttpContext,String.Join)
- 一起动手实现Windows服务程序(监控网站是否能访问) .
- 一起动手实现Windows服务程序(监控网站是否能访问)
- C# Windows服务 定时执行访问数据库循环发送手机短信
- 编写一个C#Windows服务程序,定时从数据库中拿出记录发送邮件。
- 别用Timer+Windows 服务来实现一个定时任务
- 一个有用的Windows服务小程序——用来完成Server端的Socket通信[转载]
- 一个有用的Windows服务小程序——用来完成Server端的Socket通信
- 编写一个Windows服务程序,定时从数据库中拿出记录发送邮件
- 写了一个Windows服务,通过C#模拟网站用户登录并爬取BUG列表查询有没有新的BUG,并提醒我
- 一起动手实现Windows服务程序(监控网站是否能访问)
- 对在adminstrator assistant forwindows这个工具里有一个“实例随服务启动而启动”选项的说明
- 一个定时网络唤醒的Windows 2000服务(Service)程序