用户范围设置的持久性在哪里出了问题?

发布于 12-28 07:07 字数 522 浏览 4 评论 0原文

我有一个布尔值、用户范围的设置。我通过一个名为“Settings”的引用类库来访问它。该类库有一个带有属性的模块:

Module AppSettings
 Public Property MyBooleanSetting() As Boolean
    Get
        Return My.Settings.MyBooleanSetting
    End Get
    Set(ByVal value As Boolean)
        My.Settings.MyBooleanSetting = value
        My.Settings.Save()
    End Set
 End Property
End Module

我在设置类库的属性页中定义了设置。

当其他代码操作该设置时,它将使用如下代码:

Settings.MyBooleanSetting=True

当代码运行时,此操作有效。但重新启动应用程序后,新值不会保留。 我哪里出错了?

I have a Boolean, user scoped setting. I access it through a referenced class library, called Settings. This class library has a Module with properties:

Module AppSettings
 Public Property MyBooleanSetting() As Boolean
    Get
        Return My.Settings.MyBooleanSetting
    End Get
    Set(ByVal value As Boolean)
        My.Settings.MyBooleanSetting = value
        My.Settings.Save()
    End Set
 End Property
End Module

I defined the setting in the Property pages of the Settings class library.

When other code manipulates the setting it will use code like:

Settings.MyBooleanSetting=True

While the code is running this works. But after a restart of the application the new value is not persisted.
Where am I going wrong?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

裂开嘴轻声笑有多痛2025-01-04 07:07:17

查看 在 Visual Basic 2005 中使用 My.Settings MSDN 文章并这些MSDN 论坛 线程 ,我会说您需要验证正在使用哪个路径。

用户范围设置特定于每个用户。它们可以在运行时由应用程序代码安全地读取和设置。这些设置存储在 user.config 文件中。从技术上来说准确地说,每个应用程序的每个用户有两个 user.config - 一个用于非漫游,一个用于漫游。尽管 Visual Basic 2005 文档指出 user.config 文件将根据用户名 (joe.config) 命名,但事实并非如此。 user.config 文件在 \[Local Settings]Application Data\\\ 中创建。地点:
• 是用户数据目录,可以是非漫游(上面的本地设置)或漫游。
• 是用户名。
• 是CompanyNameAttribute 值(如果可用)。否则,忽略此元素。
• 是AppDomain.CurrentDomain.FriendlyName。这通常默认为 .exe 名称。
• 是 URL、StrongName 或路径,基于可用于散列的证据。
• 是从 CurrentDomain 收集的证据的 SHA1 哈希值,按以下优先顺序排列:
a.强名称
b.URL

如果这些都不可用,请使用 .exe 路径。

• 是AssemblyInfo 的AssemblyVersionAttribute 设置。

After looking at the Using My.Settings in Visual Basic 2005 MSDN article and these MSDN Forum Threads , I would say you need to verify which path is being used.

User-scope settings are specific for each user. They can be read and set safely by the application code at run time. These settings are stored in a user.config file. To be technically accurate, there are two user.configs per user per application—one for non-roaming and one for roaming. Although the Visual Basic 2005 documentation states that the user.config file will be named according to the user's name (joe.config), this is not the case. The user.config file is created in the \[Local Settings]Application Data\\\. Where:
• is the user data directory, either non-roaming (Local Settings above) or roaming.
• is the user name.
• is the CompanyNameAttribute value, if available. Otherwise, ignore this element.
• is the AppDomain.CurrentDomain.FriendlyName. This usually defaults to the .exe name.
• is the URL, StrongName, or Path, based on the evidence available to hash.
• is a SHA1 hash of evidence gathered from the CurrentDomain, in the following order of preference:
a.StrongName
b.URL

If neither of these is available, use the .exe path.

• is the AssemblyInfo's AssemblyVersionAttribute setting.

记忆之渊2025-01-04 07:07:17

节省你们的呼吸吧伙计们。代码最终确实起作用了。我在应用程序的视图模型中使用了另一个属性来缓存Setting.MyBooleanSetting,但我忘记在应用程序启动时读取它......

Save your breath guys. The code did work after all. I used an other Property in the Viewmodel of my application that cached the Setting.MyBooleanSetting, but I forgot to read it in at application startup...

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文