Re: Cross-thread Operation Question

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Peter Duniho

    Re: Cross-thread Operation Question

    On Mon, 02 Jun 2008 17:14:31 -0700, NvrBst <nvrbst@gmail.c omwrote:
    [...]
    Any insight or references about why some do/some don't, or what's safe
    and what isn't would be appresiated (I tried searching but coudln't
    find anythign).
    The general rule is that if it's not one of the five members listed in the
    docs (under Control.Invoke and other pages), you must use Control.Invoke( )
    or Control.BeginIn voke() to access _any_ member of a Control instance.

    Now, as you've found, some members not in that list can be successfully
    used without the cross-thread exception being thrown. One that I am
    reasonably sure is okay is the Invalidate() method. As for the Text
    property, looking at the implementation for Control, I can see that it can
    cache the property value and so it stands to reason that if the value is
    cached, you wouldn't get the exception.

    Looking at both the Invalidate() method and the Text property getter, I
    can see that the implementation treats the getter (but not the setter) and
    the Invalidate() method as specifically cross-thread safe.

    Now, as a general rule, I'm not a big fan of relying on the implementation
    details. In theory, those could change at any time. But I think in this
    case, the underlying reasons that these are safe (and the setter is not
    safe) are likely to not change without some radical change within Windows
    and/or .NET.

    Which is a long way of saying that I think that you're okay not using
    Invoke() when _getting_ the Text property. I might even go further and
    say that for any member, if the cross-thread exception isn't thrown you're
    probably okay. You might even consider filing a bug against the
    documentation (http://connect.microsoft.com/) to emphasize to Microsoft
    that they ought to be more explicit in their documentation about the
    cross-thread exception and whether it's a reliable way to know whether
    Invoke() is really required. There's definitely a lot of ambiguity on the
    issue as things stand now.

    Pete
Working...