小编Ste*_*ill的帖子

Parallel.ForEach over AuthorizationRuleCollection

希望有人能指出我在这里做错了什么。我有一个读取文件访问规则的进程,我正在尝试并行运行它。

这是我到目前为止的代码:

public List<FolderAccessRule> GetSecurityGroupsForFolder(long importId, string subdirectory, bool includeInherited)
    {
        ConcurrentQueue<FolderAccessRule> groups = new ConcurrentQueue<FolderAccessRule>();
        ConcurrentQueue<Exception> exceptions = new ConcurrentQueue<Exception>();

        DirectoryInfo dInfo = new DirectoryInfo(subdirectory);
        DirectorySecurity dSecurity = dInfo.GetAccessControl();

        AuthorizationRuleCollection authorizationRuleCollection = dSecurity.GetAccessRules(true, includeInherited, typeof(NTAccount));
        Parallel.ForEach( authorizationRuleCollection,
            fsar =>
            {
                try
                {
                    FolderAccessRule group = this.GetGroup(fsar);
                    if (group != null)
                    {
                        groups.Enqueue(group);
                    }
                }
                catch (Exception e)
                {
                    exceptions.Enqueue(e);
                }
            });

        foreach (Exception e in exceptions)
        {
            string message = string.Concat(e.GetType(), "Exception getting Directory info for  ", subdirectory);
            this.RecordException(message, …
Run Code Online (Sandbox Code Playgroud)

.net c# parallel-processing access-rules

3
推荐指数
1
解决办法
564
查看次数

标签 统计

.net ×1

access-rules ×1

c# ×1

parallel-processing ×1