这就是我需要的(有点难以解释):
我有 2 个窗口控件:
主窗口和文件移动器
和 1 个 util 类:
FileMonitor
MainWindow 创建了一个新的 FileMonitor 对象,用于测试其 Loaded 事件,该事件创建一个 FileSystemWatcher 和一个 Timer 对象。
FileSystemWatcher 监视给定文件夹的 Created 和 Changed 事件,并且将计时器添加为某种事件缓冲区(例如,当将文件夹或大文件复制到正在监视的文件夹时,这会生成多个事件。我只想对第一个事件,而不是其余的)。这意味着,直到计时器停止并生成其 Elapsed 事件后,FileMover 窗口才会创建。该窗口具有一些基本的文件/文件夹复制/移动逻辑和一个用于显示当前状态的 ProgressBar 控件。
我的问题是这样的:
ProgressBar 控件在文件处理期间不会更新。仅当复制/移动方法返回时,进度条才会更新。
我尝试过使用 FileMover 的调度程序和 ProgressBar 调度程序,但这些都不起作用。
如果以上内容还不清楚,请告诉我!
这是我的来源:
来源:
http://pastie.org/1139570
(由于站点限制,必须将两个源文件放入 1 个粘贴中。 .)
here's what I need (it's a bit hard to explain):
I have 2 window controls:
MainWindow and FileMover
and 1 util class:
FileMonitor
MainWindow created a new object of FileMonitor for testing purposes on it's Loaded event, which creates a FileSystemWatcher and a Timer object.
The FileSystemWatcher watches a given folder for Created and Changed events, and the Timer is added as some kind of event buffer (when eg copying a folder or large file to the folder being watched, this generates several events. I only want to act on the first event, not the rest). This means, that not until the timer stops and generates its Elapsed event is the FileMover window created. This window has some basic file/folder copy/move logic and a ProgressBar control to show the current status.
My problem is this:
The ProgressBar control does not update during the file processing. Only when the copy/move method returns, the progress bar is updated.
I've tried using both FileMover's dispatcher and the ProgressBar dispatcher, but none of those work.
I'f the above is very unclear, let me know!
Here's my source:
Source:
http://pastie.org/1139570
(Had to put both source files in 1 paste because of site limitations..)
发布评论
评论(1)
您必须在另一个线程中加载该文件。如果没有,UI 将不会刷新。一个简单的方法是使用 BackgroundWorker-类。这是一个简短的例子:
You must load the file in another thread. If not, the UI will not be refreshed. A simple way to do this is the BackgroundWorker-class. Here a short example: