views:

208

answers:

1

I got a webapp that stores a config object in ApplicationState. This object contains the connection string to the database among other things.

Sometimes i start a async thread to do a few longer running tasks, like sending emails and updating the database.

However since this thread don't have a HttpContext i can't get at the config object.

I know this design that everything depends on HttpContext is bad, but thats too late to change now. Looking at reflector i see that the HttpContext class just uses a static internal class to get the ApplicationState. Is there any other way to get at it?

All those internal classes in .net are really annoying.

+1  A: 

Just pass whatever you like to your thread when you start it. Use a ParameterizedThreadStart delegate to start it instead of just a ThreadStart delegate. You could either pass it HttpContext.Current, or else bundle together the information you want your thread to have, and pass it.

John Saunders