码迷,mamicode.com
首页 > 编程语言 > 详细

Parallel线程使用

时间:2014-08-13 12:33:06      阅读:238      评论:0      收藏:0      [点我收藏+]

标签:des   使用   io   for   ar   cti   new   ad   

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);

Parallel线程使用,布布扣,bubuko.com

Parallel线程使用

标签:des   使用   io   for   ar   cti   new   ad   

原文地址:http://www.cnblogs.com/zhaowei303/p/3909522.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!