Avatar of eugene-g
eugene-g

asked on 

Object lifecycle - a method is being called more times then expected

In my C# .NET application I have 2 UserControl objects - PatientInformationBasic and PatientInformationDetail
The PatientInformationBasic collects basic attributes such as Last Name, first Name, etc...
The PatientInformationDetail collects additional attributes such as Phone numbers, emergency contacts, etc...
At runtime the PatientInformationBasic is being named "pib" and the PatientInformationDetail is named "pid"
In the following block of code "pib" calls various methods on "pid" and then attempts to save itself.
The details of saving process are outside of this scope. I'm using persistent object library called XPO from DeveloperExpress.
When the application is first started and an existing patient is selected for update everything goes as it should. However, when attempting to go through exact same procedure for a second time I'm noticing that the savePatient() method being called more then once. In fect, the more times I repeat this procedure the more times this methos is being called - in direct proportion with the number of times that I execute this procedure. Also, the savePatient() method only saves the data to the database first time around. All subsequent times when I have this call pop up unexpectedly more then I should it no longer saves anything. I'm attaching the code snippet as well as the movie clip of it in action
This is the code block :
 
void barButtonItemSavePatientChages_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            using (this)
            {
                checkEditShowPatientDetails.Focus();
                if (patient.Oid != -1)
                {
                    if (controlExists("pid"))
                    {
                       PatientInformationDetails pid = main.Controls["pid"] as PatientInformationDetails;
                            ArrayList addresses = pid.getPatientAddresses(patient);
                            foreach (Address address in addresses)
                            {
                                patient.Addresses.Add((Address)address);
                            }
                            MessageBox.Show("this is pib - calling pid.getEmergencyContact(patient)");
                            Person emergencyContact = pid.getEmergencyContact(patient);
                            patient.Persons.Add(emergencyContact);
                            ArrayList phones = pid.getPatientPhones(patient);
                            foreach (Phone phone in phones)
                            {
                                patient.Phones.Add((Phone)phone);
                            }
                            if (pid != null) { pid.Dispose(); }                        
                    }
                    MessageBox.Show("pib - calling patient.Save() when (patient.Oid != -1)");
                    patient.Save(); //This is the method that is being   //called more times then expected
                    if (this != null)
                    {
                        this.Dispose();
                    }
                }
}

Open in new window

.NET ProgrammingEditors IDEs

Avatar of undefined
Last Comment
eugene-g

8/22/2022 - Mon