好吧,所以我是編程新手,我想製作帶有進度條的工具欄,以顯示從互聯網獲取文件的進度並打開了,這裏是代碼snipplet http://pastebin.com/3EKrFb4K它並沒有給出錯誤的代碼,但是當我調試它說這個時,我試圖下載並打開文件(一旦它甚至不做)http://gyazo.com/44634914669d81b1c20d3d26f2dd3ad8我想知道如果它只是簡單的事情,或者如果我寫的代碼不會工作?它是一個工具條進度條,所以我必須做一些特別的或什麼?請提前幫助和感謝。C#錯誤顯示進度條顯示從互聯網上下載並運行文件的進度
0
A
回答
0
的問題是,您正在打開文件之前它已被下載:
Web客戶端的Web =新的Web客戶端(); web.DownloadFileAsync(new Uri(direct_exe_from_url),filepath); //這個方法是異步的 web.DownloadProgressChanged + = new DownloadProgressChangedEventHandler(web_DownloadProgressChanged);
Process.Start(filepath); //您在下載文件時打開該文件。
您需要執行downloadFileCompleted處理程序內的進程啓動。
這應該工作:
private void startBotToolStripMenuItem_Click(object sender, EventArgs e)
{
string directoryPath = Environment.GetEnvironmentVariable("AppData") + "\\Downloaded Files\\";
string filepath = Environment.GetEnvironmentVariable("AppData") + "\\Downloaded Files\\" + "Minecraft.exe";
if (!Directory.Exists(directoryPath))
{
Directory.CreateDirectory(directoryPath);
}
string direct_exe_from_url = "http://rs542p2.rapidshare.com/cgi-bin/rsapi.cgi?sub=download&fileid=1764003915&filename=Minecraft.exe&cookie=F2CB284BDC9920808D8494CA4EB46F0935AB22D79EC69D6D130C21FB6AD2A0A1EB413347302A46C5FB1A39599DF740D6&directstart=1";
WebClient web = new WebClient();
web.DownloadFileAsync(new Uri(direct_exe_from_url), filepath);
web.DownloadProgressChanged += new DownloadProgressChangedEventHandler(web_DownloadProgressChanged);
web.DownloadFileCompleted += new AsyncCompletedEventHandler (DownloadFileCallback);
}
void web_DownloadProgressChanged(object sender, DownloadProgressChangedEventArgs e)
{
ProgressBar1.Value = e.ProgressPercentage;
}
void DownloadFileCallback(object sender, AsyncCompletedEventArgs e)
{
string filepath = Environment.GetEnvironmentVariable("AppData") + "\\Downloaded Files\\" + "Minecraft.exe";
Process.Start(filepath);
}
相關問題
- 1. 顯示下載進度條
- 2. 用C#進度條顯示下載進度
- 3. 使用AsyncTask下載文件並在進度條中顯示進度
- 4. 下載文件時顯示進度
- 5. 上傳文件時顯示進度條
- 6. 顯示下載進度
- 7. 使進度條顯示下載狀態
- 8. 下載時顯示進度條
- 9. 顯示進度條
- 10. 顯示進度條
- 11. 如何顯示從互聯網加載數據和在UI上顯示內容的相同進度條
- 12. 從Dropbox下載文件時顯示進度條
- 13. 從服務器下載文件時顯示進度條
- 14. 進度條未顯示進度條
- 15. 在c中顯示下載進度#
- 16. jquery進度條顯示上傳文件進度
- 17. videoView進度條顯示錯誤時間
- 18. 在單個進度條中顯示下載多個文件的進度
- 19. 如何從FTP顯示下載進度
- 20. 如何顯示下載進度 - 或者是否應該顯示下載進度
- 21. 捕獲傳送進度並在進度條上顯示
- 22. 多重下載文件中的Windows Phone 8,並顯示saperate進度或進度
- 23. 顯示使用XHR2/AJAX下載文件的進度條
- 24. 當mvc中的文件下載時顯示進度條
- 25. 使用gridview時,進度條顯示錯誤進度
- 26. 使用swing GUI在下載文件時顯示進度條
- 27. 顯示角度指令文件上傳的進度條
- 28. android進度條不顯示
- 29. 顯示進度條動畫
- 30. 顯示Eclipse mini進度條?
謝謝!如果我希望它在進度條的文本infront中更新時更新,該怎麼辦? – D4rk