Solved

VB.NET Windows Service Not Runnign Code

Posted on 2009-07-14
6
140 Views
Last Modified: 2012-05-07
I have built a windows service that I want to run on every monday and the 2nd and 16th of any given month.  The service installed correctly and when I start/restart the service it runs the code, but it doesn't run it on the Mondays, 2nd, or 16th.  I put my code in below.  Any ideas on why this isn't working.  This is my first windows service I have built.  I am using a global date variable to hold the the current date as the service runs.
EventLog.WriteEntry("Dup Remover Started")
        If Date.Today <> dDate Then
            If DatePart(DateInterval.Weekday, Now()) = vbMonday Or DatePart(DateInterval.Day, Now()) = 16 Or DatePart(DateInterval.Day, Now()) = 2 Then
                'run dup checker
                'Dim CL As New Dupcl.dupClean
                'CL.Cleaner()
                Cleaner()
                EventLog.WriteEntry("Service Started On " & Date.Today)
                dDate = Date.Today
                EventLog.WriteEntry("Service Completed")
            End If
        End If

Open in new window

0
Comment
Question by:bengelhart
6 Comments
 
LVL 11

Accepted Solution

by:
loftyworm earned 125 total points
ID: 24855434
Why make this a service?
If I have something I want to run regularly, I "Schedule Task"
If it has to be a service, then make a batch file to start and stop it, and schedule that.

Otherwise, I would start with updating your ASP.net to 3.5 +patches.
0
 
LVL 83

Assisted Solution

by:CodeCruiser
CodeCruiser earned 125 total points
ID: 24857844
Make this into a windows application and schedule that application in the task scheduler.
0
 

Author Comment

by:bengelhart
ID: 24871696
will give that a try.
0
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 25037622
the code you showed is fine, AFAIK.

however, did you set up some "timed-event" to the service code runs/checks the above regularly?
0
 

Author Comment

by:bengelhart
ID: 25102250
I just scheduled the task and it works fine that way.
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.

820 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question