Hi,
I am using to UltraTabControl 6.3. I want to blink the tab when query executed sucessfully. Here is the code. Exception occurs when control backcolor changes. Due to this red X appears on tabconrol.
private void BlinkTab() { try { if (UltraTab != null) { Monitor.Enter(UltraTab); { bool blnIsOriginal = true; while (!UltraTab.Selected && !this.IsDisposed) { try { if (blnIsOriginal) { UltraTab.Appearance.BackColor = System.Drawing.SystemColors.ActiveCaption; UltraTab.Appearance.BackColor2 = System.Drawing.SystemColors.GradientInactiveCaption; blnIsOriginal = false; Thread.Sleep(500); } else { blnIsOriginal = true; UltraTab.Appearance.BackColor = Color.Empty; UltraTab.Appearance.BackColor2 = Color.Empty; Thread.Sleep(500); } } catch (Exception ex) { Console.Write("Exception in blinking."); } } UltraTab.Appearance.BackColor = Color.Empty; } } } catch (Exception ex) { BlinkTab(); } finally { Monitor.Exit(UltraTab); } } private void BlinkEvent(UltraTab pulUltraTab) { _mUltraTab = pulUltraTab; Thread objThreadBlinkTab = new Thread(new ThreadStart(BlinkTab)); objThreadBlinkTab.Start(); }
But when I run the multiple queries and wait for minutes it is giving error object reference is not instance of that object on changing the color backcolor. I am having each tab in seperate object and this function is private.
Here is exception it changes every time
System.NullReferenceException occurred Message="Object reference not set to an instance of an object." Source="Infragistics2.Win.v6.3" StackTrace: at Infragistics.Win.UIElement.GetDescendant(Type type, Object[] contexts) at Infragistics.Win.UIElement.GetDescendant(Type type, Object context) at Infragistics.Win.UltraWinTabs.TabManager.GetUIElement(ITabItem tab) at Infragistics.Win.UltraWinTabs.TabManager.DirtyTabItem(ITabItem tab, Boolean invalidate, Boolean dirtyTextMetrics, Boolean dirtyImageMetrics) at Infragistics.Win.UltraWinTabControl.UltraTabsCollection.OnSubObjectPropChanged(PropChangeInfo propChangeInfo) at Infragistics.Shared.SubObjectBase.NotifyPropChange(PropChangeInfo trigger) at Infragistics.Shared.SubObjectBase.NotifyPropChange(Enum propId, PropChangeInfo trigger) at Infragistics.Win.UltraWinTabControl.UltraTab.OnSubObjectPropChanged(PropChangeInfo propChangeInfo) at Infragistics.Win.AppearanceHolder.OnSubObjectPropChanged(PropChangeInfo propChange) at Infragistics.Shared.SubObjectBase.NotifyPropChange(PropChangeInfo trigger) at Infragistics.Shared.SubObjectBase.NotifyPropChange(Enum propId) at Infragistics.Win.AppearanceData.set_BackColor2(Color value) at Infragistics.Win.Appearance.set_BackColor2(Color value) at Thomson.Financial.Framework.Data.MarketQA.MarketQAClient.BlinkTab() in D:\SVN\Branches\.....\..\Client.cs:line 1273System.NullReferenceException occurred Message="Object reference not set to an instance of an object." Source="Infragistics2.Win.UltraWinTabControl.v6.3" StackTrace: at Infragistics.Win.UltraWinTabControl.UltraTabControlBase.get_StyleResolved() at Infragistics.Win.UltraWinTabControl.UltraTabControlBase.TabControlTabProvider.Infragistics.Win.UltraWinTabs.ITabProvider.get_Style() at Infragistics.Win.UltraWinTabs.TabManager.get_StyleResolved() at Infragistics.Win.UltraWinTabs.TabManager.get_InterTabSpacingResolved() at Infragistics.Win.UltraWinTabs.TabManager.InitializeFirstDisplayedTabItem(ITabItem tab, ScrollType scrollType, Int32 scrollIncrement, Boolean fireScrollEvents) at Infragistics.Win.UltraWinTabs.TabManager.VerifyFirstDisplayedTabItem() at Infragistics.Win.UltraWinTabs.TabManager.get_FirstDisplayedTabItem() at Infragistics.Win.UltraWinTabs.TabManager.IsTabItemInView(ITabItem tab, Boolean excludePartiallyInView) at Infragistics.Win.UltraWinTabs.TabManager.GetUIElement(ITabItem tab) at Infragistics.Win.UltraWinTabs.TabManager.DirtyTabItem(ITabItem tab, Boolean invalidate, Boolean dirtyTextMetrics, Boolean dirtyImageMetrics) at Infragistics.Win.UltraWinTabControl.UltraTabsCollection.OnSubObjectPropChanged(PropChangeInfo propChangeInfo) at Infragistics.Shared.SubObjectBase.NotifyPropChange(PropChangeInfo trigger) at Infragistics.Shared.SubObjectBase.NotifyPropChange(Enum propId, PropChangeInfo trigger) at Infragistics.Win.UltraWinTabControl.UltraTab.OnSubObjectPropChanged(PropChangeInfo propChangeInfo) at Infragistics.Win.AppearanceHolder.OnSubObjectPropChanged(PropChangeInfo propChange) at Infragistics.Shared.SubObjectBase.NotifyPropChange(PropChangeInfo trigger) at Infragistics.Shared.SubObjectBase.NotifyPropChange(Enum propId) at Infragistics.Win.AppearanceData.set_BackColor2(Color value) at Infragistics.Win.Appearance.set_BackColor2(Color value) at Thomson.Financial.Framework.Data.MarketQA.MarketQAClient.BlinkTab() in D:\SVN\Branches\.....\..\Client.cs: line 1273
It seems like you're updating the tab on a thread outside of the UI thread. This is not a safe thing to do in .NET, since you could cause sync issues like the one here. What you should do is invoke the calls that update the Appearance back to the main UI Thread in order to perform the update.
-Matt
Thanks for quick reply.I have applied as you suggested. Like this .. backgroundWorker_WorkCompleted( { objThreadBlinkTab = new Thread(new ThreadStart(BlinkTab)); objThreadBlinkTab.Start(); } private void BlinkTab() { try { bool blnIsOriginal = true; if (UltraTab != null) { while (!UltraTab.Selected && !this.IsDisposed) { if (blnIsOriginal) { DelBlinkTab delegateApply = new DelBlinkTab(ChangeTabColor); this.Invoke(delegateApply); blnIsOriginal = false; Thread.Sleep(500); delegateApply = null; } else { blnIsOriginal = true; DelBlinkTab delegateRestore = new DelBlinkTab(RestoreTabColor); this.Invoke(delegateRestore); Thread.Sleep(500); delegateRestore = null; } UltraTab.Appearance.BackColor = Color.Empty; } } } private void ChangeTabColor() { UltraTab.Appearance.BackColor = System.Drawing.SystemColors.ActiveCaption; UltraTab.Appearance.BackColor2 = System.Drawing.SystemColors.GradientInactiveCaption; } private void RestoreTabColor() { UltraTab.Appearance.BackColor = Color.Empty; UltraTab.Appearance.BackColor2 = Color.Empty; }But now another problem I am using ultratabmousemove event whenever I move mouse on tab, it pauses blinking until mouse is in moving state. Because changing of color and mouse move event activity are on the Main UI's thread that's why it pauses tab blinking. Other than mouse move if I want to change any thing in application or try to repaint the control same is happening, that is it stops the blinking unless I stop using or doing something on the application.Is there anything we can do to blink the tabs (other than the selected tab) without using the main thread?