Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. WinService issues

WinService issues

Scheduled Pinned Locked Moved C#
databasehelpquestion
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • W Offline
    W Offline
    WetRivrRat
    wrote on last edited by
    #1

    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?

    H 1 Reply Last reply
    0
    • W WetRivrRat

      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?

      H Offline
      H Offline
      Heath Stewart
      wrote on last edited by
      #2

      ServiceBase.OnStart and ServiceBase.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]

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups