解决方案 »
- C# 正则取图片Url
- 网口通信协议怎么写?
- 用户状态更新
- c#中两个窗体间的函数调用
- 讨论类的私有变量是否也以属性的方式使用呢?
- OleDb操作Excel文档的问题(如何在Excel文档中插入图片)
- 我怎么得到SqlDataReader drAnn中记录的行数,用来显示数据时分页显示
- 请问在C#中如何实现对页面及打印机的控制,急
- 关系在xslt中如何实现关联关系,我表达的不清楚,大家还是看里面的内容吧
- 问问各位大虾:::C#正式版刚出来,它跟以前的测试版有多大差别??现在市面上的有关c#的书肯定都是以测试版为标准的,是不是应该等一段
- winform 操作远程服务器指定的文件读写到本地问题
- C# 使用sendkeys.sendwait()模拟键盘,输出汉字到dos下出错
呵呵。using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.ServiceProcess;
using System.Text;
using System.IO;
using System.Timers;namespace TickService
{
public partial class Service1 : ServiceBase
{
Timer timer1; public Service1()
{
InitializeComponent();
timer1 = new Timer();
//Set the interval of timer to 3 seconds.
timer1.Interval = 3000;
//Enable the timer.
timer1.Enabled = true;
timer1.Elapsed+=new ElapsedEventHandler(timer1_Elapsed);
} protected override void OnStart(string[] args)
{
// TODO: Add code here to start your service.
//Append the text to the sample file.
StreamWriter writer = File.AppendText(@"C:\sample.txt");
writer.WriteLine("Start");
writer.Close();
} protected override void OnStop()
{
// TODO: Add code here to perform any tear-down necessary to stop your service.
//Append the text Stop to the C:\sample.txt file.
StreamWriter writer = File.AppendText(@"C:\sample.txt");
writer.WriteLine("Stop");
writer.Close();
} private void timer1_Elapsed(object sender, EventArgs e)
{
//Set the enable property to false.
//timer1.Enabled = false;
//Append the text Tick to the C:\sample.txt file.
StreamWriter writer = File.AppendText(@"C:\sample.txt");
writer.WriteLine("Tick");
writer.Close();
//timer1.Enabled = true;
}
}
}
可能执行一次就退出,也可能一直循环执行,一直到天荒地老,服务器崩溃你设置了2个timer,回调时间一个1小时,另一个1分钟
你想知道它到底有没有运行,写配置文件啊,然后看文件里的信息
光从结果上看,你第一次已经把文件都处理完了,1分钟后没有可以处理的文件,当然就不再执行了