开发者

Application settings do not allways save

I have a bit of a 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.

public Form1()
{
    oldClinicsBindingSource.DataSource = ContractFlowTool.Properties.Settings.Default.RecentClinics;
}
private void StartFind()
{
    (...)
    if (oldClinicsBindingSource.Contains(newClinic))
        oldClinicsBindingSource.Remove(newClinic);
    oldClinicsBindingSource.Insert(0, newClinic);
    oldClinicsBindingSource.EndEdi开发者_如何学Pythont();
    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. 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.

I am still curious why it was happening. Do binding sources use internal threading?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜