Where to load Static LookUpTables?

0
0

Hi.

I have a bunch of Static LookUp Table objects in order to serve the users across the application with shared data tables for look up purposes.

In order to have them available when any user logs into the application, where would be the proper place to load data in these static objects when the IIS starts the website for whatever reason?

Thanks.

Ivan

(Wisej 2.2.43.0 – C# – SQLServer)

  • You must to post comments
0
0

Thank you Luca.

Will it run even before any user opens the application? I mean, I have set the website Application Pool to Start Mode = AlwaysRunning and it Recycles every day at 4:00AM. When it recycles, will it run the Program.cs Static constructor?

What I would like to do is to fill the LookUp Tables “cache” even before any user logs into the application, avoiding any delay to any of them. For sure, I will check if the Tables are already filled and take care of sync later…

  • Luca
    • Luca
    • Mar 16, 2021 - 9:11 pm
    No. When it recycles it gets unloaded. When .NET loads the type it executes the static constructor. Web applications don’t run like desktop apps. They are just class libraries used by the web server.
  • Ivan Borges
    Thanks, Luca. I have just found out about Global.asax Application_Start. I will try and play with it to see if I can get the desired solution.
  • Luca
    • Luca
    • Mar 17, 2021 - 2:10 pm
    Global.asax Application_Start will run when the first user accesses the application. Exactly like the static constructor.
  • Ivan Borges
    Yep, but I think that in IIS 8 we get this: “This is the default configuration. Application_Start event get executed when first request is received. But you can change that through configuration in web.config. So you must use element as explained by Microsoft” ( https://stackoverflow.com/questions/50355383/webapi-application-start-will-not-fire-until-web-page-is-loaded-or-signalr-reque ). Do you think this would be a workable solution?
  • You must to post comments
0
0

You can use the static constructor of Program.cs. Static constructors are invoked the first time .NET loads a type.

 

static Program() {

}

 

 

  • You must to post comments
Showing 2 results
Your Answer

Please first to submit.