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 John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Windows service and callbacks - program sturcture

Status
Not open for further replies.

georgedumaine

Programmer
Sep 27, 2005
5
US
I have an application that uses functions in an external dll. This dll sends messages back via a callback delegate and I process the messages when they come it. On load of the main form I initialize variables and register call back. Then I call a function in the dll that plays a video file and I wait for a message that playback is completed. At this point I get the next file in a playlist and repeat the process. This all works great since my form is sitting there doing nothing (and using no resources).

The problem I'm having is in making this a windows service with no interface. Where do I wait and "do nothing" while I'm listening for messages to come back from the dll? The service has an OnStart routine that fires a timer and if I register the callback in the OnStart routine I don't see any of the messages. I wasn't successfull putting the registration in the timer either. I do get messages if I put it in a routine called by the timer but that routine has to have an infinite loop so that it isn't garbage collected and that kills my resources. I have put a sleep in the loop but this can't be the right way to deal with my problem.

Any help with this specifically or the structure of VB.NET services in general would be greatly appreciated.

George
 
I guess it matters on what you are trying to acheive, if you still want this to run as an application, I would say just make a windows app with no forms. Run the code from a module.

If you want it to run as a service, you should be able to register the callback in startup. Startup is a stub, when you open the services explorer and click on a service and tell it to start, the StartUp method is called. But if that sub doesn't complete in a few seconds, the Service explorer will throw an error. So it's best to either start a timer, or launch a new thread in the StartUp method. That way, the Startup method takes a short time to launch the new processes and then ends. That allows the Service explorer to be happy.

Another thing with Services is security. When you install them you should really give them an account to log on as (service explorer, right click, properties, LogOn tab, 'Use this account') With out that, the service has no access to network resources.

-Rick



VB.Net Forum forum796 forum855 ASP.NET Forum
[monkey]I believe in killer coding ninja monkeys.[monkey]
 
Thanks. I want it to run as a service and I'm still playing with it. I declared the callback in the timer instead of the startup routine. I'm getting messases back but I'm still having some problems. I'll let you know what I find.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top