Solved

window service will not get run my class on start

Posted on 2006-07-03
11
212 Views
Last Modified: 2010-04-23
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()

0
Comment
Question by:Padre_Corleone
  • 4
  • 2
  • 2
  • +1
11 Comments
 
LVL 48

Expert Comment

by:jpaulino
ID: 17029545
Can you provides some code ?
0
 
LVL 21

Expert Comment

by:mastoo
ID: 17030899
0
 
LVL 7

Author Comment

by:Padre_Corleone
ID: 17032091
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
 
LVL 7

Author Comment

by:Padre_Corleone
ID: 17033501
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 48

Expert Comment

by:jpaulino
ID: 17035329
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
 
LVL 7

Author Comment

by:Padre_Corleone
ID: 17035365
I did but I think I found da solution class file was coming from duferent project but same solution?
0
 
LVL 21

Expert Comment

by:mastoo
ID: 17036953
Hence my debugger comment - easy to do and quickly shows you what code is doing
0
 
LVL 7

Author Comment

by:Padre_Corleone
ID: 17221370
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
 

Accepted Solution

by:
ee_ai_construct earned 0 total points
ID: 17259991
Closed, 500 points refunded.
ee_ai_construct
Community Support Moderator
replacement part #xm34
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
Need to grow your business through quality cloud solutions? With everything required to build a cloud platform and solution, you may feel like the distance between you and the cloud is quite long. Help is here. Spend some time learning about the Con…

932 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now