erorr应用服务 [英] erorr Application service
问题描述
我想创建一个应用程序服务,但我有同样的问题。我的应用程序很简单,当我的pubblic ip地址改变时发送邮件。
所以我在无限时使用cile但是当我执行我的服务时显示错误消息广告服务保持开始。如果我在这项服务运作良好时不使用cile。
以下你看我的功能OnStart。
受保护覆盖Sub OnStart(ByVal args()As String)
EventLog.WriteEntry(MyIP正在启动)
m_oPollingThread.Start()
Dim cont As Integer = 0
虽然真实
邮件(邮件号码和续)
Threading.Thread.Sleep(60000)
cont = cont + 1
结束时
结束子
i我不明白我错在哪里
Hi,
i want create a application service but i have same problem. my application is a simple, send a mail when my pubblic ip address change.
so i use a cile while infinity but when i execute my service this show the error message ad service stay on "starting". While if i don''t use a cile while this service works well.
below you see my function "OnStart".
Protected Overrides Sub OnStart(ByVal args() As String)
EventLog.WriteEntry("MyIP is starting")
m_oPollingThread.Start()
Dim cont As Integer = 0
While true
mail("mail number " & cont)
Threading.Thread.Sleep(60000)
cont = cont + 1
End While
End Sub
i don''t understand where i mistake
推荐答案
当你的服务启动时,OnStart
调用方法。返回后,该服务被标记为已启动。但是你的方法永远不会返回 - 它将永远执行(好吧,之前cont
将大于Int32.MaxValue
,但那还有很长的路要走。因此,从服务经理的角度来看,您的服务在启动时会挂起。
如何解决?将而
块放入另一个线程。
When your service is started, theOnStart
method is called. After it has returned, the service is marked as started. But your method will never return - it will be executed eternally (OK, before thatcont
will be bigger thanInt32.MaxValue
, but that''s still very long away). Consequently, from the service manager''s point of view, your service hangs while starting.
How to resolve that? Put thatWhile
block into a different thread.
这篇关于erorr应用服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!