Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

window service will not get run my class on start

Posted on 2006-07-03
11
Medium Priority
?
220 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
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

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…
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…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
Suggested Courses

636 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