.netthread-safetydirectoryservicesaccount-managementgroupprincipal

is System.DirectoryServices.AccountManagement.GroupPrincipal thread safe?


I am writing a program that will create users in bulk, I have a operation that is part of the creation that is blocks for about 5 seconds, to get around this I was going to make it threaded and have everything sitting in a thread pool.

My question is if I create the principle outside the thread and pass the group principle to the thread and call group.Members.Add(u) and group.Save() can i get in trouble? would it be better to generate a new group principal from inside each thread?


Solution

  • From MSDN:

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

    That little note is a very common one in the documentation. It's up to you the programmer to decide what you mean by "thread safe" and how to control concurrent access.