Forums
New posts
Search forums
What's new
New posts
New profile posts
Latest activity
Members
Current visitors
New profile posts
Search profile posts
C# Community
Log in
Register
What's new
Search
Search
Search titles only
By:
New posts
Search forums
Menu
Log in
Register
Install the app
Install
VB.NET
Windows Services
Need help in writing a windows service
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
[QUOTE="jlwilliams1, post: 5840, member: 2322"] I'm trying to write a windows service routine in VB.NET and I'm using code taken straight from several examples that I've gotten from the web. The problem is that I can compile and install the service ok--it shows up in the services window from the admin tools, but it doesn't seem to be doing what it's supposed to do. Basically, I just wrote a routine that uses a timer with a 10 second tick and on every tick, an entry is supposed to written to the event log and to a text file. The strange thing is that, if I have this service up and running and I then run the program in the VS.NET IDE in debug mode, then it does what it's supposed to do--write an entry to the event log and to a text file every 10 seconds. Very strange. It just seems like nothing is happening when it is just running as a service. Here's my code: [code] Protected Overrides Sub OnStart(ByVal args() As String) ' Add code here to start your service. This method should set things ' in motion so your service can do its work. Timer1.Enabled = True Timer1.Start() End Sub Protected Overrides Sub OnStop() ' Add code here to perform any tear-down necessary to stop your service. Timer1.Stop() Timer1.Enabled = False End Sub Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick Dim i As Integer Dim na() As String Dim DataWatcherLog As New EventLog SelectStatement = "SELECT * FROM Test WHERE Newrecord = 'Y'" UpdateStatement = "UPDATE Test SET Newrecord = 'N' WHERE Newrecord = 'Y'" cmd.CommandText = SelectStatement cmd.CommandType = CommandType.Text da.SelectCommand = New SqlCommand(SelectStatement, connect) da.SelectCommand.Connection.Open() da.Fill(ds, "Test") If ds.Tables(0).Rows.Count <= 0 Then da.SelectCommand.Connection.Close() Exit Sub End If numrecs = ds.Tables(0).Rows.Count For i = 1 To numrecs ' na(numrecs) = ds.Tables("Test").Rows(numrecs - 1).Item("Address") emailmsg = emailmsg + " " + "New Record" Next If Not DataWatcherLog.SourceExists("DataWatcher") Then DataWatcherLog.CreateEventSource("DataWatcher", "DataWatcher Log") End If DataWatcherLog.Source = "DataWatcher" DataWatcherLog.WriteEntry("DataWatcher Log", emailmsg) da.SelectCommand.Connection.Close() ' Create an instance of StreamWriter to write text to a file. Dim sw As StreamWriter = New StreamWriter("TestFile.txt") ' Add some text to the file. sw.Write("This is the ") sw.WriteLine("header for the file.") sw.WriteLine("-------------------") ' Arbitrary objects can also be written to the file. sw.Write("The date is: ") sw.WriteLine(DateTime.Now) sw.Write(emailmsg) sw.Close() End Sub[/code] Can someone toss me a clue or hint please. Thanks. [/QUOTE]
Insert quotes…
Verification
Post reply
VB.NET
Windows Services
Need help in writing a windows service
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.
Accept
Learn more…
Top
Bottom