there is a way i can retrive the download speed?
Printable View
there is a way i can retrive the download speed?
Hello kleinma
I've downloaded your code and modified a bit in order to learn something new. I am really new to VB.NET. Now i've constated, that if I delete some parts of the code to let the downloader start automatically, an error occurs and says, that the access to the path was denied.
How is this possible? I am admin on my computer...
The codes i have deleted are, where you have to choose the path, the file URL and the download button. instead of theese functions i have defined some constants: 1) FileURL, 2)DownloadPath. The rest should start automatically, when the program is loaded.
Could you point me in the right direction?
Thank you in advance.
what are the values of what you hard coded? The error is pretty clear that you are trying to use some path that you don't have access to.
i have used "Application.StartupPath()" as download path.
I could see that happening on a Vista machine. Is that what you are using?
no i'm using XP media center 2005. But I have tested the program also on windows 2000 Pro... no way, access denied.
EDIT:
If it helps, I can post the script as i have changed it...
I will take a look if you post it.
OKI, here you are.
Thank you very much! :) :thumb:
I'm guessing you did change some values in here before you uploaded it to protect some info right?
The issue with your code is you are not specifying a full file name to download the file to. You are specifying a full URL, but only a directory to download to. You need to specify a directory AND filename to save the downloaded file as.
The access denied error is a bit cryptic, but that is what it means. The code is trying to open a file to write the downloaded data to, but you basically tell it to try to write the data to the folder itself, not a file in the folder.
Just use path.combine to fix this:
Code:Private Sub updater_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Try
_Downloader = New WebFileDownloader
'GET FULL FILE PATH/NAME FROM EXE PATH AND FROM URL FILE NAME
Dim DownloadedFileName As String = IO.Path.Combine(Application.StartupPath(), IO.Path.GetFileName(launcher))
_Downloader.DownloadFileWithProgress(launcher, DownloadedFileName)
Catch ex As Exception
MessageBox.Show("Error: " & ex.Message)
End Try
End Sub
Well, i added a stopwatch and then the following to try to retrieve the current speed
But it just doesn't seem to return a true speed, i measured it with DU meter and anything past about 300 kb/s seems to go amiss, this calculation is being made on the whole download, not just the chunk, when i tried the same on just a chunk stopping and resetting the stopwatch each loop, it drastically slowed down the downloadCode:currentspeed = iTotalBytesRead / (sTimer.ElapsedMilliseconds / 1000)
I also added a counter so that the calculation isn't made on every loop so that the output is still legible to humans (Only updates every 100 loops) but as above, it still slowed the download,
Any further direction or suggestions would be great
Hi
thank you my brother , it is helpful
I have a question:
how to make a button to stop "downloading" process?? how to cancel the process??
waiting you
thanks
I did it!!
I added new function named "StopDownload" and new Event "FileDownloadStopped"
download my file : WebFileDownloader.vb
then you can stop download process :
Code:_Downloader.StopDownload()
:)Code:Private Sub _Downloader_FileDownloadStopped() Handles _Downloader.FileDownloadStopped
'Write your code here
End Sub
1 - add "Timer" , Timer1 .. then Set Interval=1000Quote:
there is a way i can retrieve the download speed?
2 - In general , write :
3 - In "_Downloader_AmountDownloadedChanged" , add :Code:dim lastSize, cSize As Long
4 - In Timer1_Tick , write :Code:lastSize = cSize
If Timer1.Enabled = False Then Timer1.Enabled = True
I hope that work fine...Code:lblDownloadRate.Text = WebFileDownloader.FormatFileSize(cSize - lastSize)
lastSize = cSize
it's work fine with me
your brother:
Abdulkareem
Saudi Arabia, Jazan
hello thanks for this code..it was very usefull
quick question.. i just want to add webbrowser on this form and if i click the download links on webbrowser it is possible to automatically put the links on txtUrl?
thanks..
in theory yes you could do that.
I would imagine it would involve handling the navigating event of the browser control and checking the e.url property to see if the type of file being navigated to is one that should be downloaded. Unfortunatly this is probably something that needs to be manually coded to check for extensions (like exe, zip, etc...)
Then once you determine it is a file download, you set e.cancel to true in the navigating event to cancel the browser from doing the download, and you take the e.url property and use that to download using the progress bar downloader class from this thread.
The browser does have a filedownload event, but it does not give you any event arguments to cancel it, so I don't see how it would be useful for this scenario.
How to get download speed?
there is e function that count downloaded byte. and i know the 1byte = 8 bit. but how do i make the program to count the byte downloaded every second?
i have open 2 downloader forms. why cant they download a file each at the same time? why do the other wait for the first to finish? and if i opens 3 forms and tired it, then my program stops working.
please read my reply :
http://www.vbforums.com/showpost.php...6&postcount=97
well.. that don“nt work for me. i get like "0" or "0 byte" in the label i have to show the speed.
i dont understand how that would work because lastSize and cSize has no value. you just tell the program the they are going to have the same value.. over and over again. right?
how can i make the downloader rdy for files more than 7GB i has a file over more than 8GB but it gives me an error with this downloader what must i change in code
I don't know why people love to post something like "it gives me an error" without providing a single detail about the error, yet they expect us to know exactly how to fix the issue.
You just need to use some math to scale down the progress bar values to something acceptible to fall within the bounds of a 32 bit integer since that is what the progress bar takes for its values.
Code:Dim maximum_value As Long = (maximum value)
Dim current_value As Long = (current value)
While maximum_value > Integer.MaxValue
current_value \= 2
maximum_value \= 2
End While
Me.ProgressBar1.Maximum = CInt(maximum_value)
Me.ProgressBar1.Value = CInt(current_value)
where must i past this code?
Wherever you update the progress bar. I haven't actually looked at the control yet, this was just obvious.
kleinma is it possible to add the code to some sort of bgworker so that the app doesn't kinda hang every time the dl size gets updated? i have no idea how backgroundworkers work actually but have been told some stuff(they keep the app from going not responding).
nice code... thx for sharing =)
@Legjendat: Check my signature for my Asynchronous Downloading File System Class.
kleinma how can I change this application to be able to download files >54K. The app. is working for my smaller files but on the larger files I receive an error message at statment
Dim myWebResponse As WebResponse = wRemote.GetResponse
msg- an error occured durning download; a devise attached to the system is not functioning.
thanks
I seriously made an account here JUST to post this post.
I've uploaded a revised version of this class that include summary tags. The only thing that these '''<SUMMARY> tags do is provide a description of the function/sub/property that you are typing within IntelliSense. It makes things MUCH easier. Attached is the revised class file. Import it into your project, and you'll notice that IntelliSence provided a description for the function/sub/property AND its arguments.
Another thing I noticed was the 'Try' and 'Do / Loop' Statements within the class:
This will cause your program to freeze and become unresponsive until the download finishes if you do not run the DownloadWithProgress() on a separate thread. You should use a "BackgroundWorker" and execute this. But before running the BackgroundWorker.RunWorkerAsync(), you have to set the global property 'CheckForIllegalThreadCalls' to FALSE or else an exception will be thrown. Heres an example:Code:Do
iBytesRead = sChunks.Read(bBuffer, 0, 256)
FS.Write(bBuffer, 0, iBytesRead)
iTotalBytesRead += iBytesRead
If myWebResponse.ContentLength < iTotalBytesRead Then
RaiseEvent AmountDownloadedChanged(myWebResponse.ContentLength)
Else
RaiseEvent AmountDownloadedChanged(iTotalBytesRead)
End If
Loop While Not iBytesRead = 0
Other then that, this is a very good class. It will come to use for custom install programs, file uploaders/downloaders, file share clients, and much more. Thanks a lot for the class!Code:CheckForIllegalThreadCalls = False
BackgroundWorker1.RunWorkerAsync()
You should always use Invoke(), BeginInvoke(), etc. instead of just disabling illegal thread call checks unless client-side performance is of the issue.
Invoke() and BeginInvoke() are much more difficult to use then a simple backgroundworker. This operation does not include any serious cross-thread calls other then changing some values of progress and file sizes. Unless after the operation is finished, you could re switch the thread call checks back to "true". How would you use Invoke() or BeginInvoke() anyway? i've never used them before.
i didnt even know you could download stuff with just a progress bar :x
I'm talking about this:Quote:
Invoke() and BeginInvoke() are much more difficult to use then a simple backgroundworker. This operation does not include any serious cross-thread calls other then changing some values of progress and file sizes. Unless after the operation is finished, you could re switch the thread call checks back to "true". How would you use Invoke() or BeginInvoke() anyway? i've never used them before.
BackgroundWorker has a method called ReportProgress that uses Invoke in the background - disabling the check for illegal thread calls is not a good practice.Code:CheckForIllegalThreadCalls = False
BackgroundWorker1.RunWorkerAsync()
Invoke takes a delegate as a parameter and invokes the delegate on the UI thread.
wow,
the codes work perfect thank for this sir kleinma,
thanks so much