I have a windows service which will be running all the time, but will only activate if it has been at least 24 hours since the last time. Therefore I need to store the time and date since it last carried out it’s payload.
To do this I was thinking of writing to the App.Config with:
ConfigurationManager.AppSettings.Set("LastRunTime", DateTime.Now.ToString());
however this doesn’t seem to persist, but rather cache which is no good if the service is restarted.
So what is the accepted method for persisting values for a windows service?
I ended up serializing the object as per this article and inline with what @ChrisBint said I saved it into a text file. This is what I was looking for as ‘accepted’, I knew I could write to text files but it was the method I was looking for. I wanted to keep everything structured and strongly typed instead of writing my own methods for persisting data.
Since @Chris only provided a part answer I’ve upvoted him and accepted this.