I want to execute some code only once on start of a web service.
I thought to use void Application_Start(object sender, EventArgs e) but I have in my code
`Request.ServerVariables["SERVER_SOFTWARE"];`
and I get exception Request is not available in this context seems object probably doesn’t exist yet becase the application is just starting and not processing Requests.
Any idea how I can solve this issue ?
How I can execute my code only once .
Use a static Boolean field initialized to
falseto mark whether the function was called and set it totrueone it was called (best done at the end of the function).Only execute the code in the function if the value is
false.Do this with appropriate locking to avoid the possible race condition (thanks Yahia).