window service will not get run my class on start

I have a class file in my window service project, I have my window serivce running but t won't fire up my class.  I even tried adding my code to my actual serivce1 class so that its all under one file and when I start my service my event does not get fired up and reason what this would happen? On my start event I called my code like

getDestination()

LVL 7
Padre_CorleoneAsked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
ee_ai_constructConnect With a Mentor Commented:
Closed, 500 points refunded.
ee_ai_construct
Community Support Moderator
replacement part #xm34
0
 
Jorge PaulinoIT Pro/DeveloperCommented:
Can you provides some code ?
0
 
mastooCommented:
0
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.

 
Padre_CorleoneAuthor Commented:
Sure My code below is from my window service folder service.vb and from my class file that is under my project folder basically when i start service I want to be able to call my class and run it.  this is not what is happening.  Also when i start debugging my class file runs just fine, but when i call it from service onStart nothing happens.  am i missing somethig here?


************
Imports System.ServiceProcess
Public Class LMD_Service
    Inherits System.ServiceProcess.ServiceBase
    Public Sub New()
        ' This call is required by the Windows Form Designer.
        InitializeComponent()
        ' Add any initialization after the InitializeComponent() call.
    End Sub
    'Component Designer generated code
    Protected Overrides Sub OnStart(ByVal args() As String)
        Dim wa As New WindowsApplication2.LMDArchive()
        wa.Paths()
    End Sub

************************' my class file looks like this, basically on Start i want to call this file below
Imports System.IO
Imports System.Configuration.ConfigurationManager
Public Class LMDArchive

    Shared Sub main()
        Dim wa As New WindowsApplication2.LMDArchive
        wa.Paths()
    End Sub
    ' Chooses where to look for files and where to put them and create folder
    Public Sub Paths()
        Dim despath As String = AppSettings("DestinationPath")
        despath = despath & "\" & Today.Month.ToString & _
    "_" & Today.Day.ToString & "_" & Today.Year
        Dim sPath As String = AppSettings("SourcePath")
        txtMoveFile(despath, sPath)
    End Sub

    ' recursively run through directories and search
    Public Sub txtMoveFile(ByVal Dest As String, ByVal searchDir As String)
        ' Declare variables
        Try
            Dim di As New DirectoryInfo(searchDir)
            Dim fi() As FileInfo = di.GetFiles("*.txt")
            Dim dirs() As DirectoryInfo = di.GetDirectories()

            ' Go through each Txt file in the directory and move it if needed
            For Each fInfo As FileInfo In fi
                If File.GetCreationTime(fInfo.FullName) > Today.AddDays(-3) Then
                    If Not Directory.Exists(Dest) Then _
                       Directory.CreateDirectory(Dest)
                    File.Move(fInfo.FullName, Dest & "\" & fInfo.Name)
                End If
            Next
            ' Go through all the directories in the current directory
            For Each dir As DirectoryInfo In dirs
                txtMoveFile(Dest, dir.FullName)
            Next
        Catch ex As Exception
                  End Try
    End Sub
End Class
0
 
Padre_CorleoneAuthor Commented:
It looks like my timer works fine I wrote a log every 6  seconds and it works (just the timer) but the problem is that it won't fire up my class file, it works fine on app but i am not sure in my window service project onStart it won't call my class file

' WindowsApplication2.LMDArchive.main() is what is supposed to call my class file but it doesn't. My code works i checked it first using a form application, but now i am trying to call this same class from my timer1_handler.



Imports System.ServiceProcess
Imports System.IO
Imports System.Timers
Imports System.Configuration.ConfigurationManager
Public Class LMD_Service
    Inherits System.ServiceProcess.ServiceBase
    WithEvents tmrschedule As New System.Timers.Timer
        Public Sub New()
        ' This call is required by the Windows Form Designer.
        InitializeComponent()
        ' Add any initialization after the InitializeComponent() call.
    End Sub
    'Component Designer generated code
    Protected Overrides Sub OnStart(ByVal args() As String)
        Try
            tmrschedule.Interval = 6000
            With tmrschedule
                .Start()
                .Enabled = True
                .AutoReset = True
            End With
            EventLog.WriteEntry("My simple service started.")
        Catch ex As Exception
        End Try
    End Sub
    Protected Overrides Sub OnStop()
        With tmrschedule
            .Enabled = False
            .AutoReset = False
            .Stop()
        End With
        EventLog.WriteEntry("My simple service stopped.")
    End Sub
    Private Sub Timer1_Handler(ByVal sender As System.Object, ByVal e As ElapsedEventArgs) Handles tmrschedule.Elapsed
              Try
            EventLog.WriteEntry("Something happened")
            WindowsApplication2.LMDArchive.main()
        Catch ex As Exception
        End Try
    End Sub
0
 
Jorge PaulinoIT Pro/DeveloperCommented:
Are you using the correct windows service timer ?

You must use the timer from the components toolbox and not the timer from the window form toolbox.
0
 
Padre_CorleoneAuthor Commented:
I did but I think I found da solution class file was coming from duferent project but same solution?
0
 
mastooCommented:
Hence my debugger comment - easy to do and quickly shows you what code is doing
0
 
Padre_CorleoneAuthor Commented:
I added my class file to my window servie project and not my window app project and now I am able to run it with my timer with no problem.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.