[英]Check/understand if a file has been completely downloaded (using c#)
I wanted to develop a C# application (client side) that monitors a folder (every X seconds) in which another web application downloads files (typically Office files, PDF, ...).我想开发一个 C# 应用程序(客户端),它监视一个文件夹(每 X 秒),另一个 web 应用程序下载文件(通常是 Office 文件,PDF,...) Once the file is completely downloaded, the client application must open the document and perform other tasks/operations.
文件完全下载后,客户端应用程序必须打开文档并执行其他任务/操作。
Is there any way to check/understand when a file has been FULLY downloaded (not knowing its actual size)?有没有办法检查/理解文件何时完全下载(不知道它的实际大小)?
Best最好的
Stefano斯特凡诺
You can use a static Timer and start it from the Application_Start()
method in Global.asax
.您可以使用 static 计时器并从
Global.asax
中的Application_Start()
方法启动它。 Within Global.asax
, add the following field:在
Global.asax
中,添加以下字段:
static Timer _timer = null;
Then you can make your Application_Start()
like:然后你可以让你的
Application_Start()
像:
void Application_Start(object sender, EventArgs e)
{
if (_timer == null)
{
_timer = new Timer();
_timer.Interval = 1000; // some interval
_timer.Elapsed += new ElapsedEventHandler;
_timer.Start();
}
}
void ElapsedEventHandler(object sender, ElapsedEventArgs e)
{
string filePath = "/files/myfile.txt";
if (Directory.Exists(filePath))
{
other_tasks_operations();
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.