Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
221 views
in Technique[技术] by (71.8m points)

downloadfile - 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, ...). 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

question from:https://stackoverflow.com/questions/65841943/check-understand-if-a-file-has-been-completely-downloaded-using-c

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You can use a static Timer and start it from the Application_Start() method in Global.asax. Within Global.asax, add the following field:

static Timer _timer = null;

Then you can make your Application_Start() like:

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();
     }
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...