WinService issues
-
Ok, so if you happen to read my previous post from today you will see that i'm trying to push about .5M to a db... I have to do this by use of a service, and currently i'm having difficulty getting the service to start within the time limit that windows places on starting a service... So... How should i start the service...place it into service, and have it parse any data that is currently awaiting to be sent? maybe a better way to ask this is to say::: i need to place my service into operation, have it register as started THEN begin pushing the data over to the db... currently if i start the service with data waiting the service fails, because it can't start quick enough, becasuse its still reading the data in the logs. please note that if the log is empty the service starts fine...and runs acording to plan as i begin to populate the log file...however if i have already have data in the log then it will time-out on start up because it is still reading the data. Please help.... string Beautiful; Beautiful = "ignorant"; label1.Text = "The world is full of " + Beautiful +" people."; Why is common sense such an un-common comodity?
-
Ok, so if you happen to read my previous post from today you will see that i'm trying to push about .5M to a db... I have to do this by use of a service, and currently i'm having difficulty getting the service to start within the time limit that windows places on starting a service... So... How should i start the service...place it into service, and have it parse any data that is currently awaiting to be sent? maybe a better way to ask this is to say::: i need to place my service into operation, have it register as started THEN begin pushing the data over to the db... currently if i start the service with data waiting the service fails, because it can't start quick enough, becasuse its still reading the data in the logs. please note that if the log is empty the service starts fine...and runs acording to plan as i begin to populate the log file...however if i have already have data in the log then it will time-out on start up because it is still reading the data. Please help.... string Beautiful; Beautiful = "ignorant"; label1.Text = "The world is full of " + Beautiful +" people."; Why is common sense such an un-common comodity?
ServiceBase.OnStart
andServiceBase.OnStop
are meant for initialization and destruction of your service, respectively. They should be as fast as possible, as you've seen. Instead, push all work into a separate thread and simply start the thread.class MyDbService : ServiceBase
{
// ...
public override void OnStart(string[] args)
{
// Perhaps open the database connection and allow exceptions to be thrown
// so that the service doesn't enter a started state when its clearly won't
// do anything in such a case.
// Start your thread of execution.
Thread t = new Thread(new ThreadStart(UpdateDb));
t.Name = "Db Updater";
t.Start();
}
public override void OnStop()
{
// Make sure database connections are closed.
}
void UpdateDb()
{
// Update the database.
}
}You might also consider using a
ThreadPool
and splitting up units of work based on your inputs and number of connections available from the client to the database. If the database implements connection pooling (depends on connection string options, typically) and a client can open a number of connections to the same database you could get a lot of performance boosts this way. This posting is provided "AS IS" with no warranties, and confers no rights. Software Design Engineer Developer Division Customer Product-lifecycle Experience Microsoft [My Articles] [My Blog]