Question

Does anybody know how to check whether Windows Server AppFabric caching service is up and running programmatically?

If the AppFabric service is down, it will throws an exception. That is a very expensive process, therefore I need to check if the service is up and running before create a cache object from the AppFabric.

This means that I want to use AppFabric as a caching service only if AppFabric is running, otherwise I want to use System.Web caching.

Example:

if (checking) 
   customCache = new WebDataCache(); 
else 
   customCache = new AppFabricDataCache();
Was it helpful?

Solution

Its not that easy to do via C#. There's no management api exposed that'll allow you to check this programmatically directly. If you want to do this, you're going to have to make c# code to call the appropriate powershell cmdlet. There is an example in SO here:

You'll need to reference the system.management.automation assembly to do the business. The cmdlet you need to call is Get-CacheHost as it'll tell you whether the services are up or down. However, I've had some gotcha's with this. When you execute the cmdlet, it needs to be done under elevated rights. Also, the account your are executing it under needs to have administrative rights on the machine in the cache cluster you are pointed at. So.. this is not ideal. I tried to do this and stopped because of this.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top