Click here to Skip to main content
15,892,674 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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
Posted

1 solution

When your service is started, the OnStart 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 that cont will be bigger than Int32.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 that While block into a different thread.
 
Share this answer
 
Comments
gianLuca1978 4-Mar-13 5:08am    
ok. thanks for your advice.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900