Hi,
is the microsoft.web.administration.applicationpool.stop method asynchronous ?
The attached code returns false logging state is stopping.
How can I correctly stop application pool and wait until it is stopped without cycle with System.Threading.Thread.Sleep?
Why this behavoiur is not documented ?
Thank You
Claudio Mellina
public bool Stop()
{
var serverManager = new ServerManager();
var currentState = ObjectState.Unknown;
try
{
ApplicationPoolCollection applicationPoolCollection = serverManager.ApplicationPools;
ApplicationPool applicationPool = applicationPoolCollection[mAppPoolName];
if (applicationPool.State == ObjectState.Started)
{
SmtLogger.WriteInfo("Current application pool state is {0}", applicationPool.State);
SmtLogger.WriteInfo("Stopping application pool...");
currentState = applicationPool.Stop();
// CommitChanges to persist the changes to the ApplicationHost.config.
serverManager.CommitChanges();
SmtLogger.WriteInfo("Application pool stopped successfully. Currentstate: {0}", currentState);
}
else if (applicationPool.State == ObjectState.Stopped)
{
SmtLogger.WriteInfo("Application pool already stopped. Currentstate: {0}", currentState);
currentState = ObjectState.Stopped;
}
}
catch (Exception exc)
{
SmtLogger.WriteError("An error occurred: {0}", exc.Message);
}
return currentState == ObjectState.Stopped;
}