Search code examples
c#service

Is there a way to increase the timeout value for a single windows service in the registry in C#?


I am currently doing this below which sets the Services Pipe value as a DWord file in the registry however I am looking to only increase the timeout for a single service through the registry.

servicesPipeTimeout.SetValue("ServicesPipeTimeout", 300000, RegistryValueKind.DWord);

Solution

  • If this is for your own service, you should call the api method for requesting additional time in class ServiceBase:

    void RequestAdditionalTime(int milliseconds)
    

    You can call this method in OnContinue, OnPause, OnStart and OnStop in case you need more time.

    https://learn.microsoft.com/en-us/dotnet/api/system.serviceprocess.servicebase.requestadditionaltime?view=dotnet-plat-ext-5.0