/// <summary> /// Thread body /// </summary> /// <param name="state"></param> private void StartWork(object state) { TabView tabView = state as TabView; tab savedTab = null; tab theTab = new tab(); tabView.Merge(theTab, editMode); // Save to backend AutoResetEvent nextOneAutoResetEvent = new AutoResetEvent(false); EventHandler <save_TabCompletedEventArgs> h1 = (s, e) => { // TODO: handle error from server side savedTab = e.Result; nextOneAutoResetEvent.Set(); }; Globals.WSClient.save_TabCompleted += h1; Globals.WSClient.save_TabAsync(theTab); nextOneAutoResetEvent.WaitOne(); Globals.WSClient.save_TabCompleted -= h1; // Check return result. If failure, savedCategory will be null if (savedTab != null) { this.Dispatcher.BeginInvoke(delegate() { tabView.Restore(new TabView(savedTab)); }); } else { // Show error message this.ShowMessageWindow("Error", "Fail to save this entry. It is probably because you are trying to save a entry with conficting fields. \n'Name' and 'Url' fields are required unique for category.", false); // Back to readonly mode this.Dispatcher.BeginInvoke(delegate() { // Restore cached UI data tabView.CancelEdit(); this.itemDataForm.CancelEdit(); }); } ShopproHelper.HideBusyIndicator(this); // No unsaved item this.editMode = DataFormMode.ReadOnly; // If only one new page, return to the original one if (this.ContentPageCtx.GotoAddNewPage) { ShopproHelper.GoToContentPage(this, PageEnum.TabListPage); } }