Parallel线程使用_.NET_编程开发_程序员俱乐部

中国优秀的程序员网站程序员频道CXYCLUB技术地图
热搜:
更多>>
 
您所在的位置: 程序员俱乐部 > 编程开发 > .NET > Parallel线程使用

Parallel线程使用

 2014/8/13 11:50:54  壹站转角  程序员俱乐部  我要评论(0)
  • 摘要:publicvoidrun(Action<List<string>>onload){List<string>directoryLists=newList<string>();directoryLists=Directory.GetDirectories(m_importPath).ToList();Parallel.ForEach(directoryLists,newParallelOptions
  • 标签:使用 all 线程

public void run(Action<List<string>> onload)
        {
            List<string> directoryLists = new List<string>();
            directoryLists = Directory.GetDirectories(m_importPath).ToList();          
            Parallel.ForEach(directoryLists,new ParallelOptions { MaxDegreeOfParallelism=10}, i =>
            {
                List<string> files = importer(i);

                onload(files);

           }

     }

 

Action<List<string>> onload = dir =>
            {
                BeginInvoke(new EventHandler((obj, even) =>
                {
                    var root = new TreeNode(dir[0]);
                    for (int i = 1; i < dir.Count; i++)
                    {
                        string fileName = dir[i].Substring(dir[i].LastIndexOf('\\') + 1);
                        root.Nodes.Add(fileName.Remove(fileName.IndexOf('.')));
                    }
                    this.treeView1.Nodes.Add(root);
                }), null);

            };

import.run(onload);

发表评论
用户名: 匿名