471,336 Members | 1,254 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,336 software developers and data experts.

Re: Cross-thread Operation Question

On Mon, 02 Jun 2008 17:14:31 -0700, NvrBst <nv****@gmail.comwrote:
[...]
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.BeginInvoke() 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
Jun 27 '08 #1
0 984

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by rollasoc | last post: by
7 posts views Thread by Scott M. | last post: by
1 post views Thread by Rob Woodworth | last post: by
6 posts views Thread by ampo | last post: by
reply views Thread by rosydwin | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.