Settings.setting在调试模式下给出了不同的值 [英] Settings.setting gives the different values in Debug mode

查看:63
本文介绍了Settings.setting在调试模式下给出了不同的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

第一个奇怪之处:<​​/p>

我真的想知道为什么在调试和非调试模式下从 Settings.settings 文件中获得不同的值.换句话说,我以不调试(run->不调试启动)和调试模式(rub-> debug)启动应用程序.在这些模式下,它总是为我同一键提供不同的值.

第二个奇怪之处:<​​/p>

在运行时使用我的应用程序更改存储在 Settings.settings 文件中的值时,这些值不会更改.在Visual Studio中打开该文件时,我会看到该文件中的先前值.请注意,我不会忘记调用 Default.Save()来保存更改.

他们的原因是什么?为什么会发生它们,我该如何解决?

解决方案

原因很简单.调试时,您不会启动应用程序本身,而是启动执行代码的Visual Studio托管进程.由于设置是针对每个可执行文件的,因此您可以从VS Debugger托管的可执行文件中获得不同的先前保存的设置,就像直接启动应用程序一样.

您可以通过选择

来禁用这种奇怪的行为

项目属性-调试-

 取消选中启用Visual Studio托管过程". 

如果设置

First strangeness:

I really wonder why do I get the different values from Settings.settings file in the debug and non-debug modes. In other words I start my application in the without debugging (run-> start without debuging) and in the debug modes (rub-> debug). And it always gives me the different values for the same key in these modes.

Second strangeness:

When I change the values stored in Settings.settings file with my application at runtime, the values aren't changed. I see the previous values in this file as I open it in Visual Studio. Note I don't forget to call Default.Save() to save the changes.

What is the reason for them? Why do they occur and how do I solve them?

解决方案

The reason is simple. When you debug you do not start the application itself but a Visual Studio hosting process where your code is executed. Since settings are per executable specific you get for the VS Debugger hosted executable different previously saved settings back as if you start your application directly.

You can disable this strange behviour by selecting in your

Project Properties - Debug -

    uncheck Enable Visual Studio Hosting Process.

The settings are immutable (read only) if they are application scoped. When you call save on settings with user scope they will be stored in your user profile. The app.config contents are never changed which makes sense to allow admin only installation of an application. Later the users can change the settings by writing the "diff" to their local user profile.

这篇关于Settings.setting在调试模式下给出了不同的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆