Solved

window service will not get run my class on start

Posted on 2006-07-03
11
215 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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
 
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

749 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