I developed a Windows service using vb.net which does the following using OnStart Even...

Grabs all Entries from a SQL Table

Creates Schedules from returned rows

it works fine, schedules fire on their time and stuff.

Problem: Whenever I have to ADD a new row to my Table, I have to restart the Service, So it can Grab the Newly created rows. This is causing problems for me...there could be a task which is running already and restarting service might break the system.

So what is the best way to handle this? Can the new rows be loaded into Service without a restart?

You could mark the entries, e.g. with a flag or the date/time the row was added, and have the service periodically check for new rows. You could use an insert trigger on the table to queue messages via Service Broker for the service. It depends on whether you would rather pull or push the new data.
–
HABONov 29 '12 at 3:48

but how....OnStart event Loads all the ROWS in one shot. I cannot trigger onStart Event again with new rows. I must be missing something here.
–
highwingersNov 29 '12 at 3:53

1

OnStart will need to start another worker thread. That thread will either check the database periodically by waiting on a timer or will connect to a queue and wait for a message. How that thread integrates any new data into your schedules depends on your application. OnStart should not be doing time consuming processing. It should start one or more worker threads and then return to the service controller.
–
HABONov 29 '12 at 3:56

It would be great if you can put up a very simple basic code structure for onStart event.
–
highwingersNov 29 '12 at 3:58

There is a minimal example of coding OnStart here.
–
HABONov 29 '12 at 4:05

Note that OnStart can launch multiple threads or the first thread started may be used to start additional threads as needed. This allows you to set up either database polling or a thread that waits on a message queue for data.

A useful tip:

Adding a Main to your service allows you to run it as a console application in Visual Studio. This greatly simplifies debugging.

Use the concept of Polling into the Database. Use the System.Threading.Timer class, set some interval after which a callback method will be invoked and that will be responsible to Poll the Database for new entries.

My code is within the onStart Event of Windows Service....are you saying I should keep pooling within the onStart event? onStart Event Runs once the Service is Started and Brings all the Data into the Service.
–
highwingersNov 29 '12 at 3:49