Solved

window service will not get run my class on start

Posted on 2006-07-03
11
211 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
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 
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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

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…
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 …
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

708 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

15 Experts available now in Live!

Get 1:1 Help Now