views:

131

answers:

1

In a app i have written we delete and recreate the performance counters as the app spins up.

When running this from a console the application deletes and recreates the counters and the counter category fine.

When we run from a service, the app deletes the counter category as expected but when creating the new category it hangs until the service times out

     if (PerformanceCounterCategory.Exists(CATEGORY_NAME))
     {
        PerformanceCounterCategory.Delete(CATEGORY_NAME);
     }

Works ok but then hangs in this method

      private PerformanceCounterCategory RecreateTheCategory()
  {
     PerformanceCounterCategory category = null;
     if (!PerformanceCounterCategory.Exists(CATEGORY_NAME))
     {
        category = PerformanceCounterCategory.Create(CATEGORY_NAME, CATEGORY_HELP,
                                                     PerformanceCounterCategoryType.SingleInstance,
                                                     counterCreationDataCollection);
     }
     return category;
  }

on the .Exists line. I expect this is something to do with permissions but as in production we have to run the service as Local System I really need to fix it in code without elevating the user account

Thanks

+2  A: 

I found the solution, i needed to do my IOC build up in the OnStart() method and no the constructor

Kev Hunter
Mark your comment as the accepted answer then so we know not to come looking to try to answer it.
Alan McBee