Re: thread?

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance

From: Larry Serflaten (serflaten_at_usinternet.com)
Date: 11/02/04


Date: Mon, 1 Nov 2004 19:47:45 -0600


<hrw> wrote
> I find in the documentation the following
>
> Thread Safety
> Any public static (Shared in Visual Basic) members of this type are safe for
> multithreaded operations. Any instance members are not guaranteed to be
> thread safe.
>
> Then, I go to the members documentation and I find public methods or
> protected methods.
>
> Am I to conclude that the public methods are thread safe and the protected
> methods are not?

Not from what you posted here. Taking the members of the String class
as an example, the first Shared member is a Public Field called Empty,
the next is a Public Method called Compare. Note the S-shaped icon
on those two items. That indicates a Shared member, which is what
your Thread Safety comment was referring to. All the other properties
and methods of the String class not marked with that S-shaped icon,
are not shared. (The String type is thread safe, however)

Now look at the File class, and note it has a statement like the one
you list above. All of its members are Public Shared members, so
all of its members are thread safe.

Next up, the Graphics class. It also has a statemement like yours above,
and when you look at its members, only a few Public Methods after FromHdc
are Shared.

So to summarize what your statement says:

> Any public static (Shared in Visual Basic) members of this type are safe for
> multithreaded operations. Any instance members are not guaranteed to be
> thread safe.

For thread safety, the member has to be Public, and it has to be Shared.
(Protected methods are not Public....)

HTH
LFS

  

 



Relevant Pages

  • Re: Only static (Shared) types are thread safe ?!
    ... when the docs refer to members thread safety, ... when they say statics are thread safe, but instance are not, they mean, that ... but instance members can only be safely accessed from the ... > be thread safe." ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: Only static (Shared) types are thread safe ?!
    ... OleDbCommand class doesnt have any static members anyway ... Then why not thread safe those as well? ... >>> multithreaded operations. ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: OracleConnection Thread Safety
    ... Make sure you create a new oracleconnection instance for each thread. ... static member do not use shared variables while instance memebers ... Any instance members are not guaranteed to be thread safe." ...
    (microsoft.public.dotnet.framework.adonet)
  • Re: Only static (Shared) types are thread safe ?!
    ... > when they say statics are thread safe, but instance are not, they mean, ... but instance members can only be safely accessed from ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: IPrincipal and IsInRole
    ... FullTrust named permission set (which a developer can most likely grant to ... it doesn't only affect public methods since low accessibility ... members can be accessed via reflection. ... > My own security IPrincipal or IIdentity of type X, ...
    (microsoft.public.dotnet.security)