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




j420exe1Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

lazyberezovskyCommented:
Here is C# example of using System.Timer on Windows Service:
http://www.aspfree.com/c/a/C-Sharp/Timer-Objects-in-Windows-Services-with-C-sharp-dot-NET/

And less descriptive, but VB.NET
http://www.java2s.com/Tutorial/VB/0440__Windows/Servicetimer.htm

Core thoughts:
1) create System.Timer
2) set its interval to 60000
3) subscribe to it's Elapsed event (add code that runs query)
4) set timer's Enabled property to true on service start/continue and to false on pause/stop
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
käµfm³d 👽Commented:
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.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Development

From novice to tech pro — start learning today.