如何在不使我的应用程序无响应的情况下扫描文件并显示当前扫描? [英] How To Scan Files and Show Current Scanning Without Making My Application Non-Responding?
本文介绍了如何在不使我的应用程序无响应的情况下扫描文件并显示当前扫描?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好,
我正在c.net上开发用于.pdf文件管理的桌面应用程序.当我在任何文件夹中搜索.pdf时,会出现问题,我的应用程序停止响应了一段时间.我使用xmlwriter写入数据(即文件名,作者名,主题).我也有一个标签来显示文件的当前扫描,但仅在扫描完成后才显示最后一个文件.请帮忙!
谢谢
问候,
Gourav Goyal
Hi All,
I am developing a desktop application on c# .net for .pdf file managing. A problem occur when i search any folder for .pdf, my application stopm responding for some time. I use xmlwriter to write data(i.e. file name,author name,subject).Also i have a label to show current scanning of file but it only show last file after complition of scanning. Please help!!
Thanks
Regards,
Gourav Goyal
推荐答案
您可以尝试使用BackgroundWorker, ^ ]
You might try using a BackgroundWorker, http://msdn.microsoft.com/en-us/library/system.componentmodel.backgroundworker.aspx[^]
您要做的是使用后台工作者,然后将文件名传递回ReportProgress.这是类似的东西.
What you do is use a background worker, and pass the names of the files back in the ReportProgress. Here is something similar.
public MainWindow()
{
InitializeComponent();
ItemsSource = new ObservableCollection<string>() { "pme", "two", 3.ToString() };
DataContext = this;
var bw = new BackgroundWorker();
bw.DoWork += new DoWorkEventHandler(bw_DoWork);
bw.WorkerReportsProgress = true;
bw.ProgressChanged += new ProgressChangedEventHandler(bw_ProgressChanged);
bw.RunWorkerAsync();
}
void bw_ProgressChanged(object sender, ProgressChangedEventArgs e)
{
ItemsSource.Add(e.UserState.ToString());
}
void bw_DoWork(object sender, DoWorkEventArgs e)
{
var bw = (BackgroundWorker) sender;
for (int i = 1; i < 10000; i++)
bw.ReportProgress(i / 10000, i);
}
public ObservableCollection<string> ItemsSource { get; set; }
这篇关于如何在不使我的应用程序无响应的情况下扫描文件并显示当前扫描?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文