Windows Service questions

fkheng

Centurion
Joined
May 8, 2003
Messages
155
Location
Malaysia
When coding a Windows Service, firstly, do i need to use a timer? Can i work without a timer?

Also, how do I create a Windows Service, and then make use of a User Interface, so that when the service is started, at least I can use the interface to control certain things?
 
You dont need a timer.

Windows Services are GUIless :), you need to make another application that will modify lets say registry settings or setting files that service uses.
 
i see, ok.....

er......i have a problem, after installing the Service i created thru the VB.NET command prompt, i get an error stating FileNotFound, and that a File or assembly name or a dependancy file could not be found...

i did everything accordingly, i do not know why this error has occured...any idea?
 
Did you add any files like DLL or something that your service reads to the same folder as your service?
What file is it looking for?
 
nope...i did not add any files of that sort to my folder...

it is lookiung for some file called My, the thi ng is i can't find, in my code, any syntax or line of code which specifies this filename...

the core of my code is basicallyt this :

Visual Basic:
Private Sub Timer1_Elapsed(ByVal sender As System.Object, ByVal e As System.Timers.ElapsedEventArgs) Handles Timer1.Elapsed
        Dim MyLog As New EventLog() ' create a new event log
        ' Check if the the Event Log Exists
        If Not MyLog.SourceExists("MyService") Then
            MyLog.CreateEventSource("MyService", "Myservice Log") ' Create Log
        End If
        MyLog.Source = "MyService"
        ' Write to the Log
        MyLog.WriteEntry("MyService Log", "This is log on " & _
        CStr(TimeOfDay), EventLogEntryType.Information)
    End Sub

This is just a tutorial i followed...just to test out a Windows Service, and how to create one...

the error msg is Exception occured while initiliazing the installation. System.IO.FileNotFoundException : File or Assembly name My, or one of its dependencies, was not found..

I think I'll attach the zip file of all the related files to my project...here for your reference...
 
Last edited by a moderator:
Just unzipped your source, built the project and installed using
InstallUtil myservice.exe and everything seemed to work.
Checked under the services and Myservice was in the list, tried to start it and it started fine. So not sure what your problem was...

What did you do just prior to getting the Exception (install the service? run the service?)
 
was it wrong of me to run the service?

i am really unsure, but can u pls tell me wat i should not do...

also, there are 2 build options i realised,

one is Build the service

the other is Build the solution

wat is the difference?
 
There is no real difference, solution will build all projects that you have in soultion. If you choose to build a single project only it will be built.
That service works fine for me also.
 
It looks as though you are refering to the service as
My Service
somewhere rather than
MyService
(notice the space between the two words).

If you could give a step by step guide of what you did to get that error I could see if you did something different to me.
 
er.....okok, i'll try once i get home later tonite, i'm actually at work now, will get back to both of you later...thanx a lot, u guys have really been a lot of help to me...
 
ok, while in the Service1.vb frame, i build solution, build myservice, and then ran the InstallUtil <path> command from the VS.NET command prompt, then i get the same error again! wat cou ld be wrong man!
 
you guys really did not encounter any problem?

can u pls give me the proper sequence to do th ings so that i could try?

when do i install the service? after compiling or wat?
 
Back
Top