473,385 Members | 1,769 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

What would cause a windows service to require two starts before starting up?

I have created my first windows service and have found that it fails
when I initially start it but when I immediately try to restart the
service it starts. What could be causing this behavior? I have
included my OnStart code below. - Thanks
Protected Overrides Sub OnStart(ByVal args() As String)

'Get settings from configuration file
AppSettings = New System.Configuration.AppSettingsReader

Dim StartUpEntry As New System.Text.StringBuilder
Dim TestModeActive As Boolean = True

Monitor_AuthLocation_Timer.Enabled = False

AddHandler Monitor_AuthLocation_Timer.Elapsed, AddressOf
Monitor_AuthLocation_Timer_Tick

Try

StartUpEntry.Append("Started " & System.DateTime.Now &
vbCrLf)

'determine if in testmode
If Not (CType(AppSettings.GetValue("Mode",
GetType(System.String)), System.String).Trim.ToUpper.Equals("TEST"))
Then
TestModeActive = False
End If

'set timer interval
Try
Monitor_AuthLocation_Timer.Interval =
CType(AppSettings.GetValue("Monitor_AuthLocation_T imer.Interval",
GetType(System.String)), System.Double)
Catch ex As Exception
Monitor_AuthLocation_Timer.Interval = 0
End Try

If Monitor_AuthLocation_Timer.Interval <= 0 Or
Monitor_AuthLocation_Timer.Interval 10000 Then
Monitor_AuthLocation_Timer.Interval = 2000 ' default
to 2 seconds
End If

'establish filepaths based upon which mode of option is
being used
If TestModeActive = False Then
AuthLocation =
CType(AppSettings.GetValue("FilePath_AuthLocation" ,
GetType(System.String)), System.String)
RespLocation =
CType(AppSettings.GetValue("FilePath_RespLocation" ,
GetType(System.String)), System.String)
Else
AuthLocation =
CType(AppSettings.GetValue("FilePath_AuthLocation_ Test",
GetType(System.String)), System.String)
RespLocation =
CType(AppSettings.GetValue("FilePath_RespLocation_ Test",
GetType(System.String)), System.String)
End If
StartUpEntry.Append("AuthLocation = " & AuthLocation &
vbCrLf)
StartUpEntry.Append("RespLocation = " & RespLocation &
vbCrLf)

'Create authlocation if it does not already exist
If System.IO.Directory.Exists(AuthLocation) = False Then
System.IO.Directory.CreateDirectory(AuthLocation)
StartUpEntry.Append("AuthLocation not found...created.
" & vbCrLf)
End If

'Create resplocation if it does not already exist
If System.IO.Directory.Exists(RespLocation) = False Then
System.IO.Directory.CreateDirectory(RespLocation)
StartUpEntry.Append("RespLocation not found...created.
" & vbCrLf)
End If

'Write startup entry
AppErrLog.WriteEntry(StartUpEntry.ToString)

'establish credentials
Dim credentials As New
System.Net.NetworkCredential(username, password)
WebService.Credentials = credentials
WebService.PreAuthenticate = True

'enable monitoriing of auth location
Monitor_AuthLocation_Timer.Enabled = True

Catch ex As Exception

ex.Source = "OnStart"
Call HandleError(ex)

End Try

End Sub

Private Sub Monitor_AuthLocation_Timer_Tick(ByVal sender As
System.Object, ByVal e As System.Timers.ElapsedEventArgs)

Call Monitor_AuthLocation()

End Sub

Feb 7 '07 #1
0 1251

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: CG | last post by:
Hi I have developed a Windows Service When I try to start the Service it tells me that it cannot start as there may not be any work to do When I comment out below line of code in my OnStart...
5
by: Warning: Incoming Airstrike! | last post by:
How do I set up a program inside of a windows service to run to a point and stop, to allow it to respond to events? -- Texeme Textcasting Technology http://texeme.com Indie Pop Rocks @...
2
by: Sujatha | last post by:
Hi, I have a windows application developed which can run in system tray. I want to set up the executable to run while the OS starts. One way, i can think of doing it is by writing a windows...
28
by: joe | last post by:
I have a simple .NET application with two or three listViews which are filled with icons and when the user click on the proper item, they display the related images. I use "image = null ; " for all...
3
by: Johann Blake | last post by:
I'm developing an application in C# that needs to run as a Windows service. I'm looking for an Internet Service Provider (ISP) to host my application. Since I'm on a shoe-string budget, I can only...
2
by: Razzie | last post by:
Hey all, I wrote a Windows Service. When I test it on my developement machine (winXP) it works fine. It starts ok, never crashes, etc. When I install the service on another machine (win2000) it...
3
by: Nathan Kovac | last post by:
I have a feeling I am missing something simple, but I just can't find it. Perhaps someone can give me a lead on where to look. I will describe the issue then post my code to the web service. My...
0
by: tshad | last post by:
I have a Windows Service I created that just sets a timer and writes to EventLog every 10 seconds. It installed fine and it actually starts. But it says it doesn't. The progress bar shows the...
1
by: mikelujan | last post by:
Hi, Our application starts an external application using System.Diagnostics.Process class and the Start() method, as per code snippet below. This application run as a Windows service, and must...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.