开发者

New thread in ASP.NET app can't see web.config appsettings'm

开发者 https://www.devze.com 2023-03-04 07:00 出处:网络
Inside my ASP.NET app, I have a long running-process that I launch in a new thread.However, it throws a null reference exception when it tries to access the appsettings in my web.config.I know that th

Inside my ASP.NET app, I have a long running-process that I launch in a new thread. However, it throws a null reference exception when it tries to access the appsettings in my web.config. I know that the problem is not in my code because when I don't launch in a new thread, everything wor开发者_开发知识库ks fine.

Any suggestions?

Thanks, Dan


If you dont mind a workaround then try this.

If you have small set of appsetting information then load the app setting in to memory on application start event and then pass that info as initialization values for the thread. if web.config changed, application automatically resets.

I had smiler situation and managed to solve with above workaround.


I'm not an ASP.NET expert, so I don't know the intricacies of how the application settings are loaded, but one solution is to just pass the data from your app settings to your long running process when you start it instead of reading your app settings from the thread. This is a better design anyway as now your thread is decoupled from the app settings.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号