C#Settings.Default.Save()不节能? [英] C# Settings.Default.Save() not saving?

查看:429
本文介绍了C#Settings.Default.Save()不节能?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

此错误是非常不寻常。基本上我的代码将改变 Settings.Default.Example 然后保存并重新启动程序。然后,在加载时,它显示一个消息框。然而奇怪的是,它显示了当窗体加载一个空值

this bug is pretty unusual. Basically my code will change the Settings.Default.Example then save and restart the program. Then when it loads, it shows a message box. However oddly, it shows a empty value when the form loads.

下面是我的代码:

Main.cs
    private void Button1_Click(object sender, EventArgs e)
    {
        Settings.Default.Example = "Somevalue"; //Sets a value to the settings
        Settings.Default.Save(); // Save it
        MessageBox.Show(Settings.Default.Example); //Confirming it has been saved
        Application.Restart();
    }

    private void Main_Load(object sender, EventArgs e)
    {
        MessageBox.Show(Settings.Default.Example); // Here is the weird part, it shows empty.
    }



的MessageBox 将显示someValue中单击时按钮,然后在重新启动的applcation和的MessageBox 这显示是空的。然而,通过点击按钮再次重复这个过程并重新启动它并显示someValue中的MessageBox 。请帮忙! !非常感谢

The MessageBox will show "Somevalue" when the button was clicked then the applcation restarts and the MessageBox that showed was empty. However repeating the process by clicking the button once more and restarting it does show the "Somevalue" MessageBox. Please help! Many Thanks!

推荐答案

也许你跑了同样的错误,像我一样:设置设置的范围 应用 。这些种类的设置的保存

Maybe you ran the same mistake as I did: setting the setting's scope to Application. Those kind of settings are not saved.

将它设置为 用户 以解决问题。

Set it to User to solve the problem.

这篇关于C#Settings.Default.Save()不节能?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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