Windows 应用程序设置
我有一个用 C# (.net 3.5) 编写的 Windows 应用程序,并且有一个包含应用程序设置的 Settings.settings 文件。
当我执行这样的操作时:
Properties.Settings.Default.HSLastSend = DateTime.Now;
Properties.Settings.Default.Save();
当我重新启动应用程序时,它会被保存并保留,但是 Settings.settings 文件仍然具有原始值。我似乎找不到这个新值的存储位置。当我进入 Settings.settings 文件时,我希望它具有新值。
这是问题还是正常现象?
提前干杯,
斯图
I have a windows app written in C# (.net 3.5), and have a Settings.settings file that holds the application's settings.
When I do something like this:
Properties.Settings.Default.HSLastSend = DateTime.Now;
Properties.Settings.Default.Save();
it gets saved and persisted when I restart the application, however the Settings.settings file still has the original value. I can't seem to find where this new value is stored. I would have expected the Settings.settings file to have the new value when I went into it.
Is this a problem or normal?
Cheers in advance,
Stu
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Settings.settings 为应用程序提供默认值,而不是更改后的值,保存在您的二进制文件资源中。您可以通过在保存更改的设置后加载应用程序来证明这一点,并且您将获得更改的值,即使设置文件仍然是“旧”的。
编辑
只需注意 Properties.Settings.默认。
在 XP 计算机上,它应该位于:
C:\Documents and Settings\"YourMachineUserName"\Application Data\
Regards。
Setting.settings provide default values for the application, instead changed one, is saved in your binary file resources. You can prove it by loading your application after save changed settings, and you will get you changed value, even if Settings file has still "old" one.
EDIT
Just note that Properties.Settings.Default.
On XP machine it should be at:
C:\Documents and Settings\"YourMachineUserName"\Application Data\
Regards.
这是正常的
设置文件仅存储静态值,旨在存储
运行时应用程序设置集中放置动态值,例如
DateTime.Now 不能以这种方式存储,如果您想要当前的 DateTime 为什么不调用它
在你的代码中
This is normal
the settings file stores static values only and is designed for storing
runtime application settings in a centralized place dynamic values such as
DateTime.Now cannot be stored in this manner if you want the current DateTime why not call it
in your code