如何写一个服务,实现定期将数据库表的数据写到另一个表中.
解决方案 »
- c#显示id值不同的数据
- C#如何将两个窗体内的参数保存在同一个文本文件中,然后读取
- 如何遍历一个Form里的control将BackColor设为此类空间的默认背景色
- Body1.Attributes("bgcolor")属性设置问题?
- 加密
- 请教:怎么用C#编写游戏插件?
- 求大神解答:关于c#实现远程桌面控制 鼠标坐标问题!!
- (急)数据适配器配置问题?(高分相送)
- 关于.net,送分问题,今天结贴。
- C#C#C#C#C#C#C#C#上课上课了~~~
- 请问在WinForm下,当我在表单里的数据做了修改时,如何在关闭一个Form时产生一个提示用户保存信息的提示?
- 如何在c#中改变windows服务的启动方式?
要么用异步,要么用Timer
那我是不是要打开网页才能执行Timer啊!
using System.ServiceProcess;
using System.Diagnostics;
using System.Timers;public class SimpleService: ServiceBase {
protected Timer timer; public static void Main() {
ServiceBase.Run(new SimpleService());
} public SimpleService()
{
CanPauseAndContinue = true;
ServiceName = "Hello-World 服务"; timer = new Timer();
timer.Interval = 1000;
timer.Elapsed += new ElapsedEventHandler(OnTimer);
} protected override void OnStart(string[] args)
{
EventLog.WriteEntry("Hello-World 服务已启动");
timer.Enabled = true;
} protected override void OnStop()
{
EventLog.WriteEntry("Hello-World 服务已停止");
timer.Enabled = false;
} protected override void OnPause()
{
EventLog.WriteEntry("Hello-World 服务已暂停");
timer.Enabled = false;
} protected override void OnContinue()
{
EventLog.WriteEntry("Hello-World 服务已继续");
timer.Enabled = true;
} protected void OnTimer(Object source, ElapsedEventArgs e)
{
EventLog.WriteEntry("Hello World!");
}
}