How could I load data when the service start? As of now I host my service at console app, before my service start I load first all the information from my database into the memory ( other object hold all the information before my service ). I'm using static variable to access the data inside my sevice. I know this approach is wrong, how could I make it right. I'm using nettcp binding and it is self-hosted. Thank you in advance! :)
Asked
Active
Viewed 1,557 times
1 Answers
0
Why do you think this approach is wrong? If your data does not change at all, static variable works just fine. If you data changes but not very frequently and your application can survive with somewhat "stale" data, you can use System.Web.Caching.Cache and automatically expire data from cache based on time or other dependencies. If you don't ever want to burden your service users from waiting while your application is retrieving data from the database, you would either have to have a separate thread that monitors your database and updates cached values or use SqlCacheDependency mechanism to invalidate and refresh your cache values when underlying data changes in the database.

Dmitry Frenkel
- 1,708
- 11
- 17
-
Because I only used the console app for development phase. If I will deploy it in one of our server and install it using windows service (http://msdn.microsoft.com/en-us/library/ms733069.aspx), is it okay or possible to create object that will load all information in OnStart(string[] args) method before to start my service? – Cold Nov 19 '12 at 02:12
-
Your strategy is still solid, but instead of loading data OnStart, you could pre-load data in the service class' static constructor as mentioned here: http://stackoverflow.com/questions/739268/wcf-application-start-event – Dmitry Frenkel Nov 19 '12 at 02:23
-