public bool SaveTrainingDay(bool isWindowClosing) { if (!validateControls()) { return(false); } foreach (XtraTabPage tabPage in xtraTabControl1.TabPages) { IEntryObjectControl entryControl = (IEntryObjectControl)tabPage.Controls[0]; entryControl.UpdateEntryObject(); } if (day.Id == Constants.UnsavedObjectId && day.IsEmpty) { return(true); } day = ServiceManager.SaveTrainingDay(day); foreach (var module in PluginsManager.Instance.Modules) { module.AfterSave(UserContext.SessionData, day); } if (isWindowClosing) {//optimalization - we are closing window so we don't need to refresh the tabs (code below) return(true); } for (int index = xtraTabControl1.TabPages.Count - 1; index >= 0; index--) { XtraTabPage tabPage = xtraTabControl1.TabPages[index]; IEntryObjectControl entryControl = tabPage.Controls[0] as IEntryObjectControl; if (entryControl != null) { ParentWindow.SynchronizationContext.Send(delegate { entryControl.AfterSave(isWindowClosing); EntryObjectDTO entry = (EntryObjectDTO)tabPage.Controls[0].Tag; //here we assume that training day contains only one instance of the specific entry type var newEntry = day.GetSpecifiedEntries(entry.GetType()); if (newEntry != null) { tabPage.Controls[0].Tag = newEntry; entryControl.Fill(newEntry); } else { xtraTabControl1.TabPages.Remove(tabPage); } }, null); } } return(true); }