views:

24

answers:

1

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.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. 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.

A: 

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?

Scott Chamberlain