
本文共 3805 字,大约阅读时间需要 12 分钟。
������������Winform���������������������������������������UI���������������������������������������������������������������������������������
public delegate void AddListViewCrossThreadDelegate(******); public void AddListViewCrossThreads(ListViewItem lvi,int action) { if (lsvName.InvokeRequired) { AddListViewCrossThreadDelegate d = new AddListViewCrossThreadDelegate(AddListViewCrossThreads); lsvName.Invoke(addlistviewdelegate, lvi,action); } else { //��������������������������������������� } }
������������������������������������������������������������UI���������������������������������������������������������������������������������������������������������������������������������������������������������InvokeRequired���������������������������������������������������������������������������������������������������������������������������������Copy/Paste������������������������������������������������������������������������������������������������
���������������������������������������������������UI���������������������������������������������������������������������(���������������������������InvokeRequired)���������������������������������������������������������������������������
using System.Windows.Forms; namespace CommonUntil { public static class UIThread { public static void UIInvoke(this Control control, MethodInvoker invoker) { if (control.InvokeRequired) //��������������������������������������� { control.Invoke(invoker); //������MethodInvoker������������������Delegate��������� return; } else { invoker.Invoke(); //������������������ } } } }
���������������������������������
������������������������������lsvName���ListView���������������������ListViewItem������������������������������������addFlag������������������������������������deleteFlag���������������������������������������������������
������������ public void AddListView(ListViewItem lvi,int action) { if (addFlag == action) { this.lsvName.Items.Add(lvi); } else if (deleteFlag == action) { this.lsvName.Items.Clear(); } }
���������������������������������������������������������������������������������������ListViewItem���������action���������������������������������������������������������
������������������ for (int i = 0; i < myFiles.Count; i++) { FileInfo file = myFiles[i]; ListViewItem lvi = new ListViewItem(); lvi.Text = GetFileName.GetFileName(file.FullName); lvi.Tag = file.FullName; // store the fullname UIThread.UIInvoke(lsvName, delegate { AddListView(lvi, addFlag); } ); }
���������������������������������
UIThread.UIInvoke(lsvName, delegate { //AddListView(lvi, action); if (addFlag == action) { this.lsvName.Items.Add(lvi); } else if (deleteFlag == action) { this.lsvName.Items.Clear(); } } );
������������������������������������������������������������������������������������������������������������������������������������������
发表评论
最新留言
关于作者
