Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to manually trigger code within a service?

Status
Not open for further replies.

PPettit

IS-IT--Management
Sep 13, 2003
511
US
I've written a service that processes some files at a specified time. Every now and then, I need to process these files immediately. What's the best way to accomplish this when services don't make it easy for you to interact with the desktop?

I'd like to use something like a notifyicon in the system tray, but everywhere I look, I keep seeing posts that say this is a bad idea and recommend writing another app for communicating with the service. I'm willing to try this, but it looks like this only controls the service (stop, start, pause, etc), and not the code within the service. Am I wrong? If so, how do you trigger the specific sub?

 
Because services normally run without interaction from the user and whether or not anyone is logged on or not, it generally doesn't make sense to provide an interface.

What I generally do is provide all of my business logic in a separate dll. I then reference this dll from my service and from a regular desktop application. My service runs constantly but only checks for files when the timer ticks every 30 minutes. If I want to immediately process files, I start my regular desktop app which has a 'start', 'stop', 'progress bar', etc. interface to it. Clicking start button simply calls the same dll logic as the service. So the service and desktop have very minimal code. The real work occurs in the dll which is called from both. For my applications I've found this the easiest approach.

If you are tracking variables within your service, this setup may not work but in general I track everything critical from outside of the application by persisting it somewhere like a database or file on the server.

Would that work for you?

J
 
Thanks for the reply.

I like your approach. Being pretty new to app development, I didn't even think of using a dll like you mentioned. I'll have to look into that at some point.

What I wound up doing for now is using an external settings file that the service checks when it starts. If I need to process my files immediately, I just modify the settings file to reflect the desired execution time and then restart the service. I've already started on a regular app to monitor/control the service.


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top