Link to home
Start Free TrialLog in
Avatar of GlobaLevel
GlobaLevelFlag for United States of America

asked on

windows services - the onstart method



I am setting up a windows service...curious on the OnStart method...how do I launcha particular function inside my asp.net and/or vb.net

Its important that I launch this function as it kicks off a process...

---


Also, how do I know if I need to add installers to the service?



Public Class MyNewService

    Protected Overrides Sub OnStart(ByVal args() As String)
        ' Add code here to start your service. This method should set things
        ' in motion so your service can do its work.

        EventLog1.WriteEntry("In OnStart")

    End Sub

    Protected Overrides Sub OnStop()
        ' Add code here to perform any tear-down necessary to stop your service.
    End Sub

End Class
Avatar of arthurmnev
arthurmnev
Flag of United States of America image

Launch a function in a separate thread.

In your code you'd declare a thread variable, assign a delegate to it, and start it.
When the stop event is signaled, you need to have the thread terminate

- check on mutex, semaphore and manual reset event objects for cross thread synchronization;
- look at Interlocked function sets for variable management.
- consider using volatile variables to ensure you don't have an opportunity to work with stale / invalid data.


In reference to installers -- you do want to add those to the final project . The installers will greatly simplify your life during service installation.  Once you get the mechanics of a separate / worker thread , -- you can develop and test everything in IDE without compiling and installing the service, then just "plug" your code in.
Avatar of GlobaLevel

ASKER

any samples ..kinda new at creating a service...

once a setup is created...any way to deploy on various clients with customization..or manual setup...just wanted to drop the service on the clients and go...
To start a job in ASP.NET , you can use web services for dimpliest implementation of IPC . Essentially , your web service will make a SOAP call to a web server / web service. Since web service translates more or less into execution of a function -- once started , you can do what you need in there.
I'll try to put a sample together.

In your mind though, you need to separate the "Service" from "the application"; the service, (oversimplifying) is the same as your "Application.Run" clause for winforms. It anchors the process and prevents it from exiting. When winforms app calls Application.Run, it spawns a window that anchors your runtime. The OnStart service call, does the same, the only thing you are missing is the function that it calls (whereas Application.Run calls CreateWindow)
ASKER CERTIFIED SOLUTION
Avatar of arthurmnev
arthurmnev
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks a few questions ... Doesn't the express offer windows services?

I am writing my Asp.net code to automatically created vb. Net apps on the client that need to listen to the server... These vb.net apps will be customized based on client, do I need to programmatically create custom window services for each custom vbnet app or can I use the same windows service on each client install?  I'm Turing to make the install for window services on the client as easy as possible for the user thaks