using System.ServiceProcess;
ServiceController sc = new ServiceController(SERVICENAME);
switch (sc.Status)
{
case ServiceControllerStatus.Running:
return "Running";
case ServiceControllerStatus.Stopped:
return "Stopped";
case ServiceControllerStatus.Paused:
return "Paused";
case ServiceControllerStatus.StopPending:
return "Stopping";
case ServiceControllerStatus.StartPending:
return "Starting";
default:
return "Status Changing";
}
http://stackoverflow.com/questions/178147/how-can-i-verify-if-a-windows-service-is-running
using Microsoft.Practices.EnterpriseLibrary.Caching;
...
string cacheName = "your-cache-name";
Cache cache;
if (TryGetCache(cacheName, out cache))
{
foreach (DictionaryEntry cacheEntry in cache.CurrentCacheState)
{
object key = cacheEntry.Key;
CacheItem cacheItem = (CacheItem)cacheEntry.Value;
object value = cacheItem.Value;
Console.WriteLine("{0}: {1}", key, value)
}
}
private static bool TryGetCache(string cacheName, out Cache cache)
{
try
{
ICacheManager _cacheManager = CacheFactory.GetCacheManager(cacheName);
cache = (Cache)_cacheManager.GetType().GetField("realCache", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic).GetValue(_cacheManager);
}
catch (Exception)
{
cache = null;
return false;
}
return true;
}
http://princepthomas.blogspot.com.tr/2015/03/how-to-iterate-through-microsoft.html