Skip to content

ListBox collections have varied IsSynchronized method implementations #3088

Closed

Description

@hughbe
  • ListBox.SelectedIndexCollection and ListBox.IntegerCollection have IsSynchronized == true
  • ListBox.SelectedObjectCollection and ListBox.ObjectCollection have IsSynchronized == false

It appears both are actually not synchronized, so should return IsSynchronized == false

Activity

  1. RussKie commented on Apr 20, 2020

    @RussKie
    Contributor

    I would really appreciate if you use the templates when raising new issues. It makes triaging issues significantly easier.

  2. hughbe commented on Apr 20, 2020

    @hughbe
    ContributorAuthor

    @RussKie my apologies, will use it going forward

  3. JeremyKuhne commented on May 14, 2020

    @JeremyKuhne
    Member

    @hughbe I'd make this match the underlying behavior. If we want to make any of these truly synchronized, we can look at them individually as new features.

  4. added this to the 5.0 milestone on May 14, 2020
  5. added
    🪲 bug
    on May 14, 2020
  6. added
    help wanted
    on May 15, 2020
  7. weltkante commented on May 15, 2020

    @weltkante
    Contributor

    I'd make this match the underlying behavior.

    Note that writing code which does this generically (i.e. can deal both with an underlying collection that IsSynchronized has true or false) is hard.

    If the underlying collection has IsSynchronized==true then you can only forward methods which consist of a single access to the underlying collection. Methods which have more than one access to the underlying collection need an additional lock (_underlyingCollection.SyncObject) to keep the claim of a forwarded IsSynchronized==true correct - otherwise another thread may interleave between the two accesses (which themselves are threadsave) making the calling code not threadsafe because the operation no longer is atomic in regards to the SyncObject.

    Note that this lock is only to be done if the underlying collection claims IsSynchronized==true, if its false then this lock should not be done.

    Writing a wrapper which is aware of its underlying collection (e.g. because he created it himself) is much easier since you can special case your implementation for either case and don't have to conditionally lock.

    If you have to deal with arbitrary underlying collections you can always claim IsSynchronized==false instead of writing complex conditional locks.

    Disclaimer: its been 5+ years since I last dealt with synchronized collections (back when ASP.NET WebForms was still a thing ...) - I may remember things incorrectly.

    I mainly wanted to put out a warning that plain forwarding of IsSynchronized can easily be incorrect if the subclass/wrapper has additional logic.

  8. modified the milestones: 5.0, Future on Sep 1, 2020
  9. added
    🚧 work in progress
    on Jun 26, 2026
  10. locked and limited conversation to collaborators on Aug 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    🪲 bug🚧 work in progresshelp wanted

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions