Click to See Complete Forum and Search --> : OnStart() in Windows Service in Vb.net


Amar
01-03-2003, 03:41 PM
i have a windows service in Vb.Net. In the Onstart() method i just have one
line of code " Beep()". I have the same line of code in OnStop().
My service consists only of these 2 methods. This service runs fine after
installing and starting.
The problem comes when my application event log is full and then i try to
start my service.The service does not start. This is because the SCM tries
to write to the application event log during the OnStart() method. It does
so because by default the Autolog property of the service is True.
Now if i set this autolog property to false, it will work fine. But i am
interested in knowing if i can trap this exception that does not occour in
the method itself but somewhere in the background. And also i would really
appreciate if you could suggest me what action to take on trapping this exception.

My code is as below:

Protected Overrides Sub OnStart(ByVal args() As String)
Beep()
End Sub

Protected Overrides Sub OnStop()
Beep()
End Sub


Thanks in advance.

Russell Jones
01-04-2003, 02:41 AM
Did you try wrapping the code in your OnStart method in a Try-Catch-Finally
block? If that doesn't work, set the AutoLog property to False, and then
write appropriate starting and stopping log entries yourself. I'd be very
surprised if you can't trap the error with a Try-Catch-Finally block that
way. Let us know what happens.

"Amar" <amar.sasture@quoteadvantage.com> wrote in message
news:3e15f585$1@tnews.web.devx.com...
>
> i have a windows service in Vb.Net. In the Onstart() method i just have
one
> line of code " Beep()". I have the same line of code in OnStop().
> My service consists only of these 2 methods. This service runs fine after
> installing and starting.
> The problem comes when my application event log is full and then i try to
> start my service.The service does not start. This is because the SCM tries
> to write to the application event log during the OnStart() method. It does
> so because by default the Autolog property of the service is True.
> Now if i set this autolog property to false, it will work fine. But i am
> interested in knowing if i can trap this exception that does not occour in
> the method itself but somewhere in the background. And also i would really
> appreciate if you could suggest me what action to take on trapping this
exception.
>
> My code is as below:
>
> Protected Overrides Sub OnStart(ByVal args() As String)
> Beep()
> End Sub
>
> Protected Overrides Sub OnStop()
> Beep()
> End Sub
>
>
> Thanks in advance.
>

Chris Gallucci
01-04-2003, 01:08 PM
> Did you try wrapping the code in your OnStart method in a
Try-Catch-Finally
> block? If that doesn't work, set the AutoLog property to False, and then
> write appropriate starting and stopping log entries yourself. I'd be very
> surprised if you can't trap the error with a Try-Catch-Finally block that
> way. Let us know what happens.

I think you're going to find that the error occurs not in the Windows
Service but in the SCM. I was never able to trap this occurrence. I never
thought of resolving it using the Autolog property. I solved it by setting
the event logs' truncation property.

ChrisG