views:

48

answers:

3

We have written a custom windows service (VB.NET, .NET Framework 2.0) that takes a while to start up, because it uploads sales.

Protected Overrides Sub OnStart(ByVal args() As String)
  -- upload sales here
End Sub

That fact that it takes a long time to start up is fine, but that generates a time-out error in Windows and another program starting up does not get added to the system tray.

We can delay the sales upload, but would rather have Windows ignore the fact that this service takes a long time to start and not generate an error. Any ideas?

+4  A: 

Start the upload sales code on another thread, that'll run the upload code in the background and let the service respond that its started and you wont get the timeout message

eg

Protected Overrides Sub OnStart(ByVal args() As String)

    Dim start as new ThreadStart(UploadSalesMethod)
    Dim t as new Thread(start)
    t.Start()

End Sub
w69rdy
+3  A: 

The code in OnStart method can't run too long. So if you have a long running code there move run in under another thread so OnStart event will return earlier.

Incognito
+1  A: 

To solve your problem directly "would rather have Windows ignore the fact that this service takes a long time to start and not generate an error", you can simply increase startup timeout value by calling RequestAdditionalTime on the ServiceBase.

Al Bundy