简体   繁体   English

应用程序设置不会始终保存

[英]Application settings do not allways save

I have a bit of a Heisenbug . 我有点Heisenbug I have a list of what was recently searched for sometimes it will save the history some times it does not. 我有一份最近搜索过的内容的列表,有时它会保存历史,有时却不会。 When I attach the debugger and step through StartFind() it works every time. 当我连接调试器并逐步执行StartFind()它每次都起作用。

public Form1()
{
    oldClinicsBindingSource.DataSource = ContractFlowTool.Properties.Settings.Default.RecentClinics;
}
private void StartFind()
{
    (...)
    if (oldClinicsBindingSource.Contains(newClinic))
        oldClinicsBindingSource.Remove(newClinic);
    oldClinicsBindingSource.Insert(0, newClinic);
    oldClinicsBindingSource.EndEdit();
    while (ContractFlowTool.Properties.Settings.Default.NumberOfClinicsToRemember < oldClinicsBindingSource.Count)
    {
        oldClinicsBindingSource.RemoveAt(oldClinicsBindingSource.Count - 1);
    }
    ContractFlowTool.Properties.Settings.Default.Save();
    (..)

}
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{ //Breakpoint on this line
    ContractFlowTool.Properties.Settings.Default.Save();
}

//In Settings.Designer.cs
[global::System.Configuration.UserScopedSettingAttribute()]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
public global::System.Collections.ArrayList RecentClinics {
    get {
        return ((global::System.Collections.ArrayList)(this["RecentClinics"]));
    }
    set {
        this["RecentClinics"] = value;
    }
}

If I put a breakpoint on the { before the save inside Form1_FormClosing then hit continue (I don't even step over) it saves correctly. 如果在Form1_FormClosing内的保存之前在{上放置一个断点,然后单击继续(我什至不跳过),它将正确保存。 If the breakpoint is not there it does not save. 如果断点不存在,则不会保存。

The program does use background workers in other parts but they not being run in my test case case. 该程序确实在其他部分使用了后台工作程序,但是在我的测试用例中它们并未运行。

Any help would be greatly appreciated. 任何帮助将不胜感激。

Commenting out the Save() inside StartFind() appears to have fixed it. StartFind()中的Save()似乎已解决了该问题。

I am still curious why it was happening. 我仍然很好奇为什么会这样。 Do binding sources use internal threading? 绑定源是否使用内部线程?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM