I have two buttons that share the same WorkerThread. One button creates a new shipment, while the other one refreshes a grid. But I get an occational exception even though I have everything in a try-catch brackets.
The buttons look like this:
CreateNewShipment
if( WorkerThread != null ) { while( WorkerThread.ThreadState == ThreadState.Running ) { Thread.Sleep(1000); } WorkerThread = new Thread( new ThreadStart(CreateNewShipment)); WorkerThread.Start(); } else { WorkerThread = new Thread( new ThreadStart(CreateNewShipment)); WorkerThread.ApartmentState = ApartmentState.MTA; WorkerThread.IsBackground = false; WorkerThread.Start(); } |
RefreshGrid
if( WorkerThread != null ) { while( WorkerThread.ThreadState == ThreadState.Running ) { Thread.Sleep(1000); } WorkerThread = new Thread( new ThreadStart(RefreshPickTickets)); WorkerThread.Start(); } else { WorkerThread = new Thread( new ThreadStart(RefreshPickTickets)); WorkerThread.ApartmentState = ApartmentState.MTA; WorkerThread.IsBackground = false; WorkerThread.Start(); } |
But the exception I am getting looks like this:
System.NullReferenceException: Object reference not set to an instance of an object. at Infragistics.Win.UIElement.DrawChildElements(UIElementDrawParams& drawParams) at Infragistics.Win.UIElement.DrawElement(UIElementDrawParams& defaultDrawParams) at Infragistics.Win.UIElement.DrawChildElements(UIElementDrawParams& drawParams) at Infragistics.Win.UIElement.DrawElement(UIElementDrawParams& defaultDrawParams) at Infragistics.Win.UIElement.DrawChildElements(UIElementDrawParams& drawParams) at Infragistics.Win.UIElement.DrawElement(UIElementDrawParams& defaultDrawParams) at Infragistics.Win.UIElement.DrawChildElements(UIElementDrawParams& drawParams) at Infragistics.Win.UIElement.DrawElement(UIElementDrawParams& defaultDrawParams) at Infragistics.Win.UIElement.DrawChildElements(UIElementDrawParams& drawParams) at Infragistics.Win.UIElement.DrawElement(UIElementDrawParams& defaultDrawParams) at Infragistics.Win.UIElement.DrawChildElements(UIElementDrawParams& drawParams) at Infragistics.Win.UIElement.DrawElement(UIElementDrawParams& defaultDrawParams) at Infragistics.Win.UIElement.DrawHelper(Graphics graphics, Rectangle invalidRectangle, Boolean doubleBuffer, AlphaBlendMode alphaBlendMode, Boolean clipText, Boolean forceDrawAsFocused) at Infragistics.Win.UIElement.Draw(Graphics graphics, Rectangle invalidRectangle, Boolean doubleBuffer, AlphaBlendMode alphaBlendMode) at Infragistics.Win.ControlUIElementBase.Draw(Graphics graphics, Rectangle invalidRectangle, Boolean doubleBuffer, AlphaBlendMode alphaBlendMode, Size elementSize) at Infragistics.Win.ControlUIElementBase.Draw(Graphics graphics, Rectangle invalidRectangle, Boolean doubleBuffer, AlphaBlendMode alphaBlendMode) at Infragistics.Win.UltraWinGrid.UltraGridUIElement.Draw(Graphics graphics, Rectangle invalidRectangle, Boolean doubleBuffer, AlphaBlendMode alphaBlendMode) at Infragistics.Win.UltraControlBase.OnPaint(PaintEventArgs pe) at Infragistics.Win.UltraWinGrid.UltraGrid.OnPaint(PaintEventArgs pe) at System.Windows.Forms.Control.PaintWithErrorHandling(PaintEventArgs e, Int16 layer, Boolean disposeEventArgs) at System.Windows.Forms.Control.WmPaint(Message& m) at System.Windows.Forms.Control.WndProc(Message& m) at System.Windows.Forms.ControlNativeWindow.OnMessage(Message& m) at System.Windows.Forms.ControlNativeWindow.WndProc(Message& m) at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam) |
And I have no idea what it means... :(
Could someone take a time and give me some guidance here
Thank you very much for your time

Threading errors, clueless
Hatawa
You were right, I set the WorkerThread off and when it is finished it will update the text in my statusbar at the bottom, and it is update-ing the DataSource in my Grid.
In the Method that the WorkerThread executes I have these two lines of code:
this
.Grid.DataSource = ds; Working( false );ShowStatusbarInfo( "Table refreshed" );
Are these the functions I would need to use Invoke instead
Would I have to put the this. prefix or will that make it reference the WorkerThread itself perhaps
AceWeb
My guess is that you are performing some action on the other threads (non UI threads) that affect the UI components. This is not supported. You'll need to perform an Invoke or BeginInvoke call when interacting with UI components on a non-UI thread.< xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />
-mark
Program Manager
Microsoft
This post is provided "as-is"