本文介绍了如何停止后台下载器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 我正在尝试在后台下载文件。通过一项小型研究,我发现了这个小类: C#.NET后台文件下载器。您将在该链接中找到整个代码。 所以我的问题是我无法删除下载的文件,直到我的表单关闭。我如何处理文件,以便我可以删除它们?我尝试使用downloader.Stop();然而,这不是诀窍。手柄未配置。我也试过downloader.IsBusy = false;这是相同的,但它也没有用。 我很确定我在这里错过了一些简单的东西。对不起烦恼。 这是尝试删除文件时抛出的异常: An未处理的类型' System.IO.IOException'发​​生 in mscorlib.dll 附加信息:进程无法访问文件' C:\ Users \ path \ download.exe'因为 正由另一个进程使用。 我正在做什么的小型复制品。 downloader.LocalDirectory = mp3Path; downloader.Files.Clear(); downloader.Files.Add( new FileDownloaderApp.FileDownloader.FileInfo(aLinks [Link])); downloader.Start(); // Thread.Sleep(500); downloader.DeleteCompletedFilesAfterCancel = true ; downloader.Stop(); downloader.IsBusy = false ; // Thread.Sleep(500); File.Delete(mp3Path + \\ + downloader.CurrentFile.Name); 我正在尝试为curropted文件/链接执行此操作。解决方案 选项#1:加载 文章页面 ,找到评论和讨论,点击添加评论或问题并提出问题;作者将收到通知,并有机会回答你。 或者,选项#2:拿我的HttpDownloader,其中大部分代码都写在了本质上下载,没有所有UI(仅限控制台),可以继续下载或部分下载的文件,修改它以满足您的需要。由于此代码直接逐块实现读/写循环,因此很容易实现: 如何从互联网上下载文件 。 有些背景,另见: FTP:下载文件 , 如何从Asp.net 2.0中的服务器下载文件 。 -SA I am trying to download a file in the background. With a small research i did i found this small class: C# .NET Background File Downloader. You will find the entire code in that link.So my problem is that i can't delete the downloaded files until my form is closed. How can i dispose the files so i can delete them? I tried using downloader.Stop(); however that was not the trick. The handle is not disposed. I also tried downloader.IsBusy = false; which is the same but it didn't work neither.I am pretty sure i am missing something simple here. Sorry for the troubles.This is the exception thrown when trying to delete the file:An unhandled exception of type 'System.IO.IOException' occurred in mscorlib.dllAdditional information: The process cannot access the file 'C:\Users\path\download.exe' because it is being used by another process.A small reproducer of what i am doing.downloader.LocalDirectory = mp3Path;downloader.Files.Clear();downloader.Files.Add(new FileDownloaderApp.FileDownloader.FileInfo(aLinks[Link]));downloader.Start();//Thread.Sleep(500);downloader.DeleteCompletedFilesAfterCancel = true;downloader.Stop();downloader.IsBusy = false;//Thread.Sleep(500);File.Delete(mp3Path + "\\" + downloader.CurrentFile.Name);I am trying to do this for curropted files/links. 解决方案 Option #1: load the article page, locate "Comments and Discussions", click "Add a Comment or Question" and ask a question; the author will be given a notification and a chance to answer you.Alternatively, option #2: take my HttpDownloader, which has mostly the code written on the essence of downloading, without all that UI (console-only) and can continue downloading or a partially downloaded file, modify it to suit your needs. As this code directly implements the reading/writing loop block by block, it will be very easy to do: how to download a file from internet.For some background, see also:FTP: Download Files,how to download a file from the server in Asp.net 2.0.—SA 这篇关于如何停止后台下载器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
07-18 11:45