Hello,
I'm getting the InvalidOperationException whenever I scroll in an UltraGrid.
It happens randomly when I'm scrolling, especially if I hold down the mouse button over the scroll bar background to get the scroll bar to move to that location.
Nothing is being called when I scroll, just a cross thread issue between winforms and the grid
Here is the exception:
System.InvalidOperationException HResult=0x80131509 Message=Cross-thread operation not valid: Control 'ugData' accessed from a thread other than the thread it was created on. Source=System.Windows.Forms StackTrace: at System.Windows.Forms.Control.get_Handle() at System.Windows.Forms.Control.PointToClientInternal(Point p) at System.Windows.Forms.Control.PointToClient(Point p) at Infragistics.Win.ButtonUIElementBase.VerifyMouseOverButton() at Infragistics.Win.ScrollButtonUIElement.n(Object ) at System.Threading.TimerQueueTimer.CallCallbackInContext(Object state) at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx) at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx) at System.Threading.TimerQueueTimer.CallCallback() at System.Threading.TimerQueueTimer.Fire() at System.Threading.TimerQueue.FireNextTimers() at System.Threading.TimerQueue.AppDomainTimerCallback()
Any ideas? Thanks!
This is for a future person who runs into this. I found the same issue in upgrading an OLD .Net app from 2.0 to 4.7. Fortunately we bought the source code license so I was able to debug and recompile the control assembly to fix this. Here is my solution.
The ScrollButtonUIElement class has a SystemTimerCallback function that has two calls to this.VerifyMouseOverButton. These calls are made from the timer thread, not the UI thread. To fix this I changed the code
from:
this.VerifyMouseOverButton();
to
if (control.InvokeRequired) control.Invoke(new MethodInvoker(this.VerifyMouseOverButton)); else this.VerifyMouseOverButton();
This fixes the error (if you have the source code).
Cheers!
I took a look at this code in this area and it looks like this issue was fixed way back in 2005. So it would only be a problem in a really old version of the controls.