What you really want to do here is caching.
When you application launches, it's going to need to get some data from a database or whatever storage you are using to populate your cache.
The logic I use here is like this...
Cache Logic Diagram[
^]
So, the first time you call a method, it will invoke the database operation and cache the data. Next time you call the method, the data is retrieved from the Cache.
You can implement this using a CacheManager class, source as follows
NB: this using the HttpRuntime caching mechanism, so you'd need a reference to System.Web in your project
PasteBin source code for CacheManager[
^]
You can then call like follows...
public delegate TValue DataRetrievalDelegate<TValue>();
public System.Data.DataTable GetCityData()
{
return CacheManager.RetrieveFromCacheOrInvoke<System.Data.DataTable>("Cache:CityData",
new DataRetrievalDelegate<System.Data.DataTable>(delegate()
{
return new System.Data.DataTable();
}));
}
I've put together a little demo project if you're struggling with this.
Retrieve From Cache Or Invoke Demo[
^]
Have a look in the Program.cs file. Put a breakpoint on the first line...run the project through line by line.
Notice how the first time it will call the delegate method, the second time it will retrieve from the cache
:thumbsup: