我需要处理它之前以编程方式下载大文件。什么是最好的方式来做到这一点?由于文件很大,我想要特定的时间等待,以便我可以强制退出。如何以编程方式下载大文件在C#中
我知道WebClient.DownloadFile的()。但似乎没有办法确定等待时间来强制退出。
try
{
WebClient client = new WebClient();
Uri uri = new Uri(inputFileUrl);
client.DownloadFile(uri, outputFile);
}
catch (Exception ex)
{
throw;
}
的另一种方法是使用命令行实用程序(wget的)要下载的文件,并触发使用的ProcessStartInfo和使用过程WaitForExit命令(INT毫秒)强行退出。
ProcessStartInfo startInfo = new ProcessStartInfo();
//set startInfo object
try
{
using (Process exeProcess = Process.Start(startInfo))
{
//wait for time specified
exeProcess.WaitForExit(1000 * 60 * 60);//wait till 1m
//check if process has exited
if (!exeProcess.HasExited)
{
//kill process and throw ex
exeProcess.Kill();
throw new ApplicationException("Downloading timed out");
}
}
}
catch (Exception ex)
{
throw;
}
有没有更好的方法?请帮忙。谢谢。
什么是URI ?这是FTP吗? – t0mm13b 2010-02-15 23:20:27