Home Forums WinForms controls Xceed Grid for WinForms Cross-thread operation not valid

Viewing 14 posts - 1 through 14 (of 14 total)
  • Author
    Posts
  • User (Old forums)
    Member
    Post count: 23064
    #16137 |

    I have been experiencing this error {“Cross-thread operation not valid: Control ” accessed from a thread other than the thread it was created on.”} while running my program and I have no clue how/where it throws this exception. I have looked into MSDN: http://msdn.microsoft.com/en-us/library/ms171728(vs.80).aspx and tried to fix the problem with using the Invoke method as described. But I still experience this error from time to time.

    The stack trace shows the following:

    at System.Windows.Forms.Control.get_Handle()

       at System.Windows.Forms.Control.DestroyHandle()

       at System.Windows.Forms.Control.Dispose(Boolean disposing)

       at Xceed.Editors.WinTextBox.Dispose(Boolean disposing)

       at Xceed.Editors.WinNumericTextBox.Dispose(Boolean disposing)

       at System.ComponentModel.Component.Dispose()

       at Xceed.Grid.Editors.CellEditorManager.Dispose(Boolean disposing)

       at Xceed.Grid.Editors.CellEditorManager.Dispose()

       at Xceed.Grid.Column.DisposeCachedManagerNotFromManagerList(IDisposable manager)

       at Xceed.Grid.Column.Finalize()

    Any help would be much appreciated! Thanks.

     

    Imported from legacy forums. Posted by Sop (had 3976 views)

    User (Old forums)
    Member
    Post count: 23064

    Well, there is no doubt that some UI is being access from a thread different from the thread on which the UI is running.

     In Visual Studio, you can open the Threads window (go to Debug -> Windows -> Threads, at runtime when debugging), which will permit you to see on which thread the different calls to your methods/events are made, and it should help you find out where and when you need to call Invoke, so the calls are redirected on the UI thread.

    Imported from legacy forums. Posted by André (had 778 views)

    User (Old forums)
    Member
    Post count: 23064

    I tried commenting out all other threads in my program and re-run it. I still got the error. It seems to me that the error would be thrown if I open a form (which contains a grid and some buttons) and close the form (by clicking a button on the form) and doing this repeatedly for several times. It is really strange that a cross-thread operation could happen. From the stack trace, it shows something about disposing a grid element. I wonder what the stack trace tells about. Also, any help regarding this cross-thread operation error would be much appreciated. I really have no clue how to fix/debug it further. Thanks.

    System.InvalidOperationException was unhandled

      Message=”Cross-thread operation not valid: Control ” 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.DestroyHandle()

           at System.Windows.Forms.Control.Dispose(Boolean disposing)

           at Xceed.Editors.WinTextBox.Dispose(Boolean disposing)

           at Xceed.Editors.WinNumericTextBox.Dispose(Boolean disposing)

           at System.ComponentModel.Component.Dispose()

           at Xceed.Grid.Editors.CellEditorManager.Dispose(Boolean disposing)

           at Xceed.Grid.Editors.CellEditorManager.Dispose()

           at Xceed.Grid.Column.DisposeCachedManagerNotFromManagerList(IDisposable manager)

           at Xceed.Grid.Column.Finalize()

     

    Imported from legacy forums. Posted by Sop (had 1582 views)

    User (Old forums)
    Member
    Post count: 23064

    The text appeared hard to read. I re-posted the stack trace as below:

     

     

    System.InvalidOperationException was unhandled

      Message=”Cross-thread operation not valid: Control ” 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.DestroyHandle()

           at System.Windows.Forms.Control.Dispose(Boolean disposing)

           at Xceed.Editors.WinTextBox.Dispose(Boolean disposing)

           at Xceed.Editors.WinNumericTextBox.Dispose(Boolean disposing)

           at System.ComponentModel.Component.Dispose()

           at Xceed.Grid.Editors.CellEditorManager.Dispose(Boolean disposing)

           at Xceed.Grid.Editors.CellEditorManager.Dispose()

           at Xceed.Grid.Column.DisposeCachedManagerNotFromManagerList(IDisposable manager)

           at Xceed.Grid.Column.Finalize()

    Imported from legacy forums. Posted by Sop (had 1115 views)

    User (Old forums)
    Member
    Post count: 23064

    Have you been able to solve this problem? I am getting the same exception, and it also seems to happen under the same circumstances (open and close a Form containing a grid).

    I only started getting this exception when I upgraded from Xceed Grid version 2.5 to version 3.7. Before this upgrade, the application in question has been used for several months.

    Imported from legacy forums. Posted by ronny (had 790 views)

    User (Old forums)
    Member
    Post count: 23064

    Working with a customer on this, we may have found a problem, but since we do not reproduce it here, it is a bit difficult to be sure.  There may be a workaround for the issue, but we did not test it on our side.  However, it worked for the customer I mentioned.

    Before closing the form containing the grid, set the CellEditorManager to null on the columns on which you have NOT set a CellEditorManager, and then call ResetCellEditorManager(). This way, the DEFAULT editor should be correctly released before the GC tries to clean it up, and it may prevent the exception.  If you delete a column without closing the grid, you can do the same, as you would likely have the same exception if you don’t.

    e.g.:

    gridControl1.Columns[

    “column1” ].CellEditorManager = null;

    gridControl1.Columns[

    “column1” ].ResetCellEditorManager();

     

    Imported from legacy forums. Posted by André (had 687 views)

    User (Old forums)
    Member
    Post count: 23064

    Thanks André,

    This work-around works for me.

    Imported from legacy forums. Posted by ronny (had 1011 views)

    Xceed Support
    Member
    Post count: 5658

    Clarification

    To prevent the “Cross-thread operation not valid: Control”  problem do the following:

    set

    .CellEditorManager = null;
    .ResetCellEditorManager();

    on the columns that are using the default editors.

    For example:

        Dim column As Column

        For Each column In GridControl1.Columns
          column.CellEditorManager = Nothing
          column.ResetCellEditorManager()
        Next
     

    Imported from legacy forums. Posted by Mohamed [Xceed] (had 1265 views)

    User (Old forums)
    Member
    Post count: 23064

    in form load write  Windows.Forms.Control.CheckForIllegalCrossThreadCalls = False
    hopely u will naver face this problem again…

    Imported from legacy forums. Posted by Muhammad (had 762 views)

    User (Old forums)
    Member
    Post count: 23064

    The problem is not at Form_Load, but when the form is closed, and comes from the Garbage Collector (GC), thus CheckForIllegalCrossThreadCalls will not help in this situation.

    Imported from legacy forums. Posted by André (had 709 views)

    User (Old forums)
    Member
    Post count: 23064

    Do we have an eta on when a patch will be released for this.   This is causing us some “issues” as we use grids on a lot of screens.  

     

    I tried creating decendant grid destructor; but apparently it isn’t being called before this problem occurs(???), meaning I have to change a lot of screens to add code to try and fix this.

     Nathan.

    Imported from legacy forums. Posted by Nathanael (had 715 views)

    User (Old forums)
    Member
    Post count: 23064

    A fix for this will be available in our next service release, which should come out sometime before the end of September.

    Imported from legacy forums. Posted by André (had 845 views)

    User (Old forums)
    Member
    Post count: 23064

    Would gridControl1.Clear() possibly casue the cross-thread operation exception as well?

    I have a refresh method which would call gridControl1.Clear() and then re-populate the grid. It seems to me that if I refresh the grid, the cross-thread exception will then throw out at some point. And if I never refresh the grid, the program seems running fine without the exception thrown. However, I am not certain if it is related to the gridControl1.Clear() method or it is some other factors which cause the cross-thread exception.

    Thanks.

    Imported from legacy forums. Posted by Sop (had 765 views)

    User (Old forums)
    Member
    Post count: 23064

    Have you tried the latest version, to see if the issue is still there?  The GridControl.Clear() clears everything including columns, which would produce the issue stated above when conditions are met (i.e. the default editors are not cleared right when the GC passes).

    Imported from legacy forums. Posted by André (had 2024 views)

Viewing 14 posts - 1 through 14 (of 14 total)
  • You must be logged in to reply to this topic.