As part of our build and deploy code, we have timeout issues related to stopping and starting a service.
Here is the code that stops the service
public DeploymentChangeSummary StopService(WebPublisherParameters parameters)
{
var sourceOptions = new DeploymentBaseOptions();
var destinationEndpointOptions = new DeploymentBaseOptions()
{
ComputerName = parameters.DestinationComputer
};
var destProviderOptions = new DeploymentProviderOptions(DeploymentWellKnownProvider.RunCommand)
{
Path = "Net Stop " + parameters.DestinationName
};
using (var sourceObj =
DeploymentManager.CreateObject(new DeploymentProviderOptions(DeploymentWellKnownProvider.RunCommand), sourceOptions))
{
return sourceObj.SyncTo(destProviderOptions, destinationEndpointOptions, new DeploymentSyncOptions());
}
}
We are having timeout issues and ulitmately a failed build because the service does not stop in time.
We tried configuring the waitInterval like this
destProviderOptions.ProviderSettings["waitInterval"] = 20000;
but realised that it was a read only configuration, so I was wondering if anyone could point us in the right direction to do this programmatically rather than using the command line option.
Thanks Tapashya
You need to set RetryInterval of DeploymentBaseOptions object. Edited code from the question.
public DeploymentChangeSummary StopService(WebPublisherParameters parameters)
{
var sourceOptions = new DeploymentBaseOptions();
var destinationEndpointOptions = new DeploymentBaseOptions()
{
ComputerName = parameters.DestinationComputer
};
var destProviderOptions = new DeploymentProviderOptions(DeploymentWellKnownProvider.RunCommand)
{
Path = "Net Stop " + parameters.DestinationName
};
using (var sourceObj =
DeploymentManager.CreateObject(new DeploymentProviderOptions(DeploymentWellKnownProvider.RunCommand), sourceOptions))
{
destinationEndpointOptions.RetryInterval = 2 * 1000; // Set wait interval to 2 minutes
return sourceObj.SyncTo(destProviderOptions, destinationEndpointOptions, new DeploymentSyncOptions());
}
}