Menu

Cross Thread Operation Failing

Help
eiredrake
2014-12-19
2022-02-24
  • eiredrake

    eiredrake - 2014-12-19

    Greetings,

    Been a long time user of ObjectListView and love it.

    Having a problem now though. I have a form with an OLV on it and it receives an event to tell it when a Dictionary<Type,List<IModuleReport>() collection is updated so I can make it refresh the OLV.

    When this happens, the data shows up just fine but when I call AutoSizeColumns() seemingly nothing happens. After debugging into the AutoSizeColumns() method I discovered that an invalidoperation exception is occurring because the code is attempting to get the width of a columnHeader which was created in the original UI thread.

            this.processResultList.SetObjects(data);
            this.processResultList.AutoSizeColumns();
    

    Message: Cross-thread operation not valid: Control 'processResultList' accessed from a thread other than the thread it was created on.

    The error is occurring in ObjectListView.cs line 3943 -

    switch(column.Width) // BOOM - InvalidOperationException

    Is there any way for me to get around this without modifying the OLV code myself?

    Thanks
    Ed Kramer

     
  • Phillip Piper

    Phillip Piper - 2015-01-04

    As noted in the FAQ, only a limited set of operations are thread safe.

    You will need to use BeginInvoke(). Have a look inside SetObjects() to see how it works.

     
  • SIMON ALEMAN

    SIMON ALEMAN - 2022-02-24

    I am getting The thread 0x11f90 has exited with code 259 (0x103) on form load. What would cause that?

     

Log in to post a comment.