开发者

Windows service startup causing a windows error

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 no开发者_运维百科t generate an error. Any ideas?


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


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜