I decided to try to create a windows service (that looks for rows every minute in a particular table in a database and does something when it finds a row in that table) today and when I first dove into the Visual Studio project I realized something. I didn't know where to put the things I wanted to happen while the service was running.
Yes, this is a very newbie thing for windows services, but it just didn't seem very easily understandable like other projects have been in the past.
This is what I seen when I first created the project after selecting the "View Code" part of the designer:
I guess this is typical. At least I know where to put the code when I'm starting and stopping the service.
Well, here I am. Lost. Where do I put my code to check the database.
Thank God for google. I did a little searching and found a great post at:
Best part was this:
"When you start the service, Windows won't get feedback that the service has started, since the service blocks in the OnStart call. Windows will promptly report an appropriate error. Another catch is that you can't tell the service to stop, because it never leaves the OnStart event!"
I tried putting everything in the OnStart method in the past and could never figure out why my service wasn't working right.
This tutorial saved my life. Not really, but it did help me to figure out why my windows service would never start if I put everything in the OnStart method.
My answer was this: I need to put my "Working code" into it's own thread. After I got this revelation, things started flowing a little easier.