Link to home
Start Free TrialLog in
Avatar of Jeff Fillegar
Jeff FillegarFlag for United States of America

asked on

VB.NET windows service that queries a database

I am developing in VB using VS 2008.
Requirement:
Need to query a table to get a work queue id.  Need to run query every 60 seconds.  If query returns id, then do some work...if result set is empty then wait 60 seconds (or some time interval) before executing query again.  This task needs to run in the background on a workstation.

After browsing experts exchange, google, etc..., it seems that a Windows Service should be created for this task instead of a console app.    

Looking for examples to get me started in creating the windows service.  

I have the vb.net code to query the database.  So, just looking for an example of how to contruct the service.  Should this code be placed in the OnStart() or should I create another class/module/function and call from/to?  

Should I have an infinite loop that executes the query every 60 seconds in the OnStart() or is that not needed since the windows service inherently is supposed to run "forever"?  Is this how the "Timer" comes into play?  How do I add the System Timer instead of the Forms Timer?

Recommendations? Thoughts?  Examples?

Thanks in advance,
Jeff




ASKER CERTIFIED SOLUTION
Avatar of lazyberezovsky
lazyberezovsky
Flag of Belarus 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
Avatar of kaufmed
The OnStart() method MUST return within about 10 - 15 seconds (otherwise Win automatically shuts it down) in order for your service to be started. To do tasks in a service, you either need to spawn a new thread or use a timer as lazyberezovsky described.