8,737
社区成员
发帖
与我相关
我的任务
分享
ObservableCollection<NameInfo> nameList = new ObservableCollection<NameInfo>();
dgvDate.ItemsSource = nameList;
thread_create = new Thread(() =>
{
CreateName();
});
thread_create.Start();
public void CreateName()
{
List<NameInfo> list = NameClass.CreateNormalName();
Dispatcher.BeginInvoke(DispatcherPriority.Normal, new updateDateGridDelegate(() =>
{
progress.Maximum = list.Count;
}));
for (int i = 0; i < list.Count-1; i++)
{
Dispatcher.BeginInvoke(DispatcherPriority.Normal, new updateDateGridDelegate(() =>
{
lock (nameList) //加载出来的数据会有很多重复的。貌似需要lock但是没效果
{
//dgvDate.Items.Add(list[i]);
nameList.Add(list[i]);
progress.Value = i;
}
}));
Thread.Sleep(1);//如果不休眠会卡主
}
}