遍历 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()));
// }
// }
}*/
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()));
// }
// }
}*/
解决方案 »
- 如何用函数实现这个打开窗体的简单功能??
- 关于获得窗口控件句柄的问题,急!!!!!!!!!
- SQLserver2005安装后的疑问?跪求
- “引用类型”做函数参数,在函数中处理可以保留值,那用object装箱的变量却不会被保留值?
- 超级简单!设计frm窗体时,窗体内容太多排列不下想让窗体出现纵向滚动条该怎么做?
- 如何2次循环读出数据库记录
- mschart 怎么在客户端显示
- 大家好,小生向高手们问一个C#写ACCESS的问题
- [菜鸟请教] 如何自己编写MDI菜单代码实现诸如权限控制之类的操作
- 怎样向Word文件中的指定位置插入指定格式的文字?
- C1FlexGrid的SubTotal函数
- 如果全国有数个客户端从我的服务器数据库服务器获取数据的话,我用客户端程序直接连接SQLServer数据库的方法是否可行,望高手指点!
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
}