Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
465
Threading with UltraListView
posted

Hi

After reading hundreds of lines of text about threading and keeping everything thread safe I still do not get the following.

I have created on my main thread Items into a UltraListView, now at another time(not at creation) on another worker thread I want to update a subitem and or the text of the main column. So using a keyIndex linked to the MainColumn Item I use Dim intIndex as Integer = UltraListView1.Items.IndexOf(ItemKey) to return the required index if available. If a valid index is returned then I use Dim clmX as UltraListViewItem = UltraListView1.Items(intIndex) to make a reference to the object. When I need to set the Text property I use the Invoke as required on the clmX and pass it to the correct thread.

Now as I do not get a cross thread error when returning the IndexOf and no error when getting the clmX object is this method classed as thread safe?

Should I be using a Invoke to get the IndexOf or Invoking to get a UltraListViewItem for reference in the Dim?

-Paul

Parents
  • 469350
    Offline posted

    Hi Paul,

    No Windows Forms controls are thread-safe. I am including the Infragistics controls as well as the inbox controls. I suppose there might be some other third-party controls out there that are, but if so, I am not aware of them.

    It's hard to understand from your description what you are trying to do here. But you cannot refer to the control from another thread. There is no safe way to do that. So if you have a line of code like:

    Dim intIndex as Integer = UltraListView1.Items.IndexOf(ItemKey)

    And this code exists on the worker thread, that's a problem. There is no safe way to make that work, because you simply cannot reference a control that exists on the UI thread from a background thread safely.

    FPSI said:
    Now as I do not get a cross thread error when returning the IndexOf and no error when getting the clmX object is this method classed as thread safe?

    The fact that you are not getting an error is not indicative that this is a safe operation. In fact, one of the hallmarks of threading problems is that code like this often seems to work find and then causes an exception somewhere else in the code that is seemingly unrelated. This is why threading issues are do difficult to debug.

Reply Children