.NET 4.0异步文件拷贝 [英] .net 4.0 asynchronous file copy

查看:189
本文介绍了.NET 4.0异步文件拷贝的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有小的.NET 4.0应用程序,它基本上比较文件日期,如果文件被更改copyes这些从位置到B位置。虽然这个副本的任务完成了,它会显示有进度条等小UI。

I have small .net 4.0 application which basically compares file dates, if the files are changed copyes these from location a to location b. While this copy job is done, it displays little UI with progress bar etc.

如何以异步方式做到这一点的文件上次写入时间比较和文件副本?作为即时通讯开始做这项权利的程序启动之后,应用程序UI加载很慢,用户界面​​不更新correcty(正如我的应用程序正在等待文件拷贝等)。

How to do this file last write time comparision and file copy asynchronously? As im starting to do this right after the app is started, the app ui is loading very slowly and ui is not updated correcty (as my app is waiting file copy etc).

编辑:
......我想从长时间运行的任务文件更新UI,BackgroundWorker的大约有其他选择选项这一点,但什么呢?

...and I want to update the UI from long running file task, BackgroundWorker has option for this but what about other options?

推荐答案

您可以使用<一个href=\"http://msdn.microsoft.com/en-us/library/system.componentmodel.backgroundworker%28v=vs.110%29.aspx\"相对=nofollow> BackgroundWorker的为这种类型的事情:

You can use a BackGroundWorker for this type of thing:

BackGroundWorker worker = new BackGroundWorker();
worker.DoWork += myWorkDelegate; // method, delegate or lambda that does the heavy work
worker.RunWorkerCompleted += myCompletedDelegate; //method delegate or lambda to execute when DoWork has finished

worker.RunWorkerAsync();

这篇关于.NET 4.0异步文件拷贝的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆