/// <summary> /// Executes when a Start command is sent to the service by the Service Control Manager. /// </summary> /// <param name="args">Data passed by the start command.</param> protected override void OnStart(string[] args) { try { // Reading service configuration settings from its configuration file Configuration.ReadConfigParams(); /// /// Configure this service to receive backing store events /// NamedCache cache = CacheFactory.GetCache(Configuration.CACHE_NAME); BackingStorePolicy policy = new BackingStorePolicy(); // We want to receive asynchronous write-behind events from StateServer: policy.EnableAsyncOperations = true; // Our customized IBackingStore implementation that knows how to write a cached // object to the database: BackingStoreAdapter adapter = new BackingStoreAdapter(); // Register to handle backing store events: cache.SetBackingStoreAdapter(adapter, policy); Logger.WriteMessage(TraceEventType.Information, 1, $"[OnStart] Backing store adapter was successfully registered for handling events in named cache '{Configuration.CACHE_NAME}'"); } catch (Exception ex) { Logger.WriteError(2, ex); throw; } }