windows服务问题

PigAndCat 2007-03-30 05:14:02
windows服务安装成功.但是OnStart方法不执行
在服务中增加timer1控件 设置 每5秒执行一次.在timer1_Tick事件中
发送mail的方法.但是都执行不成功.请问是什么问题

...全文
371 15 打赏 收藏 转发到动态 举报
写回复
用AI写文章
15 条回复
切换为时间正序
请发表友善的回复…
发表回复
dmondeo 2007-04-25
  • 打赏
  • 举报
回复
tower6277() 正解,timer.tick好像是在winform中用的。
impeller 2007-04-23
  • 打赏
  • 举报
回复
用Thread代替Timer吧
tower6277 2007-04-23
  • 打赏
  • 举报
回复
在服务里不能用timer.tick事件,得用timer.elapse事件
这个Timer得自己添加,名字空间:system.timer
哈哈007哈 2007-04-08
  • 打赏
  • 举报
回复
看看onstart里面做了什么
ruan_hg 2007-04-08
  • 打赏
  • 举报
回复
onstart里面只写timer.start()
具体要执行的写在timer_click中
参考
ms-help://MS.VSCC.v80/MS.MSDN.v80/MS.VisualStudio.v80.en/dv_radcon/html/e24d8a3d-edc6-485c-b6e0-5672d91fb607.htm
wangsaokui 2007-04-08
  • 打赏
  • 举报
回复
查看事件管理器中是否有事件的记录就知道服务是否启动,或者调试下服务也可以,具体的做法你可以在google上查一下
wangsaokui 2007-04-08
  • 打赏
  • 举报
回复
Windows服务是没有界面的,所以“在服务中增加timer1控件 设置 每5秒执行一次.在timer1_Tick事件中”是没有办法执行成功的,可以考虑用线程,比如

using System.Thread;

...................

while(true)
//这里的true不是个好主意,应该根据你具体的服务启动要求,否则会是一个
//无法退出的线程
{
Add_EventLog("Mylog", "MylogSource", "now run" + System.DateTime.Now.ToString("hh:mm:ss"));
Thread.Sleep(5000);//线程停止5秒
}

其中Add_EventLog见下:

public static void Add_EventLog(string Custom_Log, string Event_Source, string Event_content)
{
if (EventLog.SourceExists(Event_Source))
{
//增加一个新事件实例
EventLog.DeleteEventSource(Event_Source);
EventLog.CreateEventSource(Event_Source, Custom_Log);
}
else
{
EventLog.CreateEventSource(Event_Source, Custom_Log);
}

EventLog eventLog1 = new EventLog(Custom_Log);
eventLog1.Source = Event_Source;
eventLog1.WriteEntry(Event_content, EventLogEntryType.Information);
}
duke731 2007-04-08
  • 打赏
  • 举报
回复
顶,我也在找这个问题
ylqmf 2007-04-01
  • 打赏
  • 举报
回复
up
Jinwmmail 2007-03-30
  • 打赏
  • 举报
回复
"每5秒执行一次.在timer1_Tick事件中"

时间设长点试试.
yan63 2007-03-30
  • 打赏
  • 举报
回复
把错误输出来或写到evenlog里,安装后可能要手动启动
应该看看系统日志,把有用信息帖一下,这样子不能看出发生了什么
北京的雾霾天 2007-03-30
  • 打赏
  • 举报
回复
你可以在Start方法中用事件日志记录一些信息用来做为调试信息,单独的调试Start方法很难做到.
mabaolin 2007-03-30
  • 打赏
  • 举报
回复
不清楚,帮顶了
北京的雾霾天 2007-03-30
  • 打赏
  • 举报
回复
在服务管理里不能启动吗?

110,533

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧