Hello,
i am developing a Sharepoint Service Application. Within the Service, parallel worker threads are started at unpredictable times, and background loops are running for up to 30 minutes. Upon certain occurrences, i recycle the Application Pool. From then on,
no new worker threads are started, and long running loops are aborted. This works quite fine so far.
On the other hand, scheduled Application Pool recycling (by IIS Manager) is not recognized within the service, and occasionally, the App Pool Recycling times out and disables the Application Pool.
i tried two ways to obtain the current Application Pool Status:
By Web Administration API:
ServerManager serverManager = new ServerManager(); ApplicationPoolCollection applicationPoolCollection = serverManager.ApplicationPools; foreach (ApplicationPool applicationPool in applicationPoolCollection) { if (applicationPool.Name == appPoolId) { State = applicationPool.State; break; } }
or by Active Directory:
string appPoolPath = "IIS://localhost/W3SVC/AppPools/" + appPoolId; DirectoryEntry appPoolEntry = new DirectoryEntry(appPoolPath); //App Pool property: AppPoolState int nState = Convert.ToInt32(appPoolEntry.Properties["AppPoolState"][0]); if ((nState & 8) != 0)// stopped { State = ObjectState.Stopped; } else if ((nState & 4) != 0)// stopping { State = ObjectState.Stopping; } else if ((nState & 2) != 0)// started { State = ObjectState.Started; } else if ((nState & 1) != 0)// starting { State = ObjectState.Starting; }
I expected that after occurrence of an application pool recycle, the state would change. Unfortunately, it didn't. I get "Started" right until the process disappears.
Anyone has an idea about how to detect an externally induced Application Pool Recycle from within the service process?
With best regards,
Joachim