繁体   English   中英

检查/了解文件是否已完全下载(使用 c#)

[英]Check/understand if a file has been completely downloaded (using c#)

我想开发一个 C# 应用程序(客户端),它监视一个文件夹(每 X 秒),另一个 web 应用程序下载文件(通常是 Office 文件,PDF,...) 文件完全下载后,客户端应用程序必须打开文档并执行其他任务/操作。

有没有办法检查/理解文件何时完全下载(不知道它的实际大小)?

最好的

斯特凡诺

您可以使用 static 计时器并从Global.asax中的Application_Start()方法启动它。 Global.asax中,添加以下字段:

static Timer _timer = null;

然后你可以让你的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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM