当前位置:编程学习 > C#/ASP.NET >>

Dictionary类怎么用backgroundWorker实现多线程

遍历 Dictionary只能用foreach吧,怎么实现backgroundWorker和Dictionary集合类的多线程,下面代码该如何修改
  private string RetrieveData(BackgroundWorker worker, DoWorkEventArgs e)
        {
            string maxRecords = (string)e.Argument;
            /*int percent = 0;
            for (int i = 1; i <= maxRecords; i++)
            {
                if (worker.CancellationPending)
                {
                    return i;
                }


                percent = (int)(((double)i / (double)maxRecords) * 100);
                 //foreach (KeyValuePair<string, NameWord> a in NanName)
               //{
               //     foreach (KeyValuePair<string, NameWord> b in NanName)
               //     {
                        {
                            percent = (int)(((double)i / (double)maxRecords) * 100);
                            worker.ReportProgress(percent, new KeyValuePair<int, string>(i,a.Value.Name.ToString()));
                                //a.Value.Name.ToString() + b.Value.Name.ToString()));
                      //  }
                 // }
                }*/ --------------------编程问答-------------------- 帮顶  --------------------编程问答-------------------- 急啊,谁能帮忙解答下吗 --------------------编程问答-------------------- 参考 --------------------编程问答-------------------- Dictionary用foreach遍历,怎么实现backgroundWorker一行一行读出来 --------------------编程问答-------------------- 看看foreach的原理。
foreach等价于:

            Dictionary<string, string> dic = new Dictionary<string, string>();
            dic.Add("1", "value1");
            dic.Add("2", "value2");
            KeyValuePair<string, string> pair;
            Dictionary<string, string>.Enumerator enumerator = dic.GetEnumerator();
            while (enumerator.MoveNext())
            {
                pair = enumerator.Current;
                Console.WriteLine(pair.Value); //or do what you want
            }
补充:.NET技术 ,  C#
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,