473,385 Members | 1,872 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

DownloadFile locks application

I have this Class:

Imports System.Net
Public Class DownloadFile
Private _webClt As WebClient
Private _url As String
Private _file As String

Sub New(ByVal urlSource As String, ByVal fileDestination As
String)
_url = urlSource
_file = fileDestination
End Sub
Sub DownloadFile()

_webClt = New WebClient
_webClt.DownloadFile(_url, _file)
_webClt = Nothing

End Sub
End Class
It works well. However, I wish to continuesly read the size of the
file written (show activity for the user), but DownloadFile locks the
application until it has finished downloading the file.

How can I make the form-update independent from the download - or
otherwise prevent the app from locking?

Any other comments to my class is welcomed, since i'm new to .Net.

Regards /Snedker
Nov 21 '05 #1
6 1297
You need to do the download in a seperate thread from the form.

Dim DF as new DownloadFile Class
Dim t As System.Threading.Thread
t = New System.Threading.Thread(AddressOf DF.DownloadFile)
t.Start()

Now create a property in your DownloadFile class that returns the progress
amount. Do a loop in the form something like

Do While DF.CurrentProgressPercent < 100
'Update Progress Bar in here
'Now sleep for a short time
System.Threading.Thread.CurrentThread.Sleep(500) 'I think
that's close to the class that you need, don't have ide on this puter
Loop
'Close the thread
t.abort()

That's the idea. Syntax might not be perfect cause I wrote it on the fly.
Chris

"Morten Snedker" <morten_spammenot_ATdbconsult.dk> wrote in message
news:sg********************************@4ax.com...
I have this Class:

Imports System.Net
Public Class DownloadFile
Private _webClt As WebClient
Private _url As String
Private _file As String

Sub New(ByVal urlSource As String, ByVal fileDestination As
String)
_url = urlSource
_file = fileDestination
End Sub
Sub DownloadFile()

_webClt = New WebClient
_webClt.DownloadFile(_url, _file)
_webClt = Nothing

End Sub
End Class
It works well. However, I wish to continuesly read the size of the
file written (show activity for the user), but DownloadFile locks the
application until it has finished downloading the file.

How can I make the form-update independent from the download - or
otherwise prevent the app from locking?

Any other comments to my class is welcomed, since i'm new to .Net.

Regards /Snedker

Nov 21 '05 #2
Nak
Hi Morten,

I recommend looking at my WTR application, it has a reusable class for
downloading ansync via HTTP complete with progress tracking.

http://www.members.lycos.co.uk/nickp...p/soft-wtr.htm

It's not fun cancelling one of those once it's waiting for the callback
to be fired, but it seems to work quite well in the application mentioned
above.

Nick.

"Morten Snedker" <morten_spammenot_ATdbconsult.dk> wrote in message
news:sg********************************@4ax.com...
I have this Class:

Imports System.Net
Public Class DownloadFile
Private _webClt As WebClient
Private _url As String
Private _file As String

Sub New(ByVal urlSource As String, ByVal fileDestination As
String)
_url = urlSource
_file = fileDestination
End Sub
Sub DownloadFile()

_webClt = New WebClient
_webClt.DownloadFile(_url, _file)
_webClt = Nothing

End Sub
End Class
It works well. However, I wish to continuesly read the size of the
file written (show activity for the user), but DownloadFile locks the
application until it has finished downloading the file.

How can I make the form-update independent from the download - or
otherwise prevent the app from locking?

Any other comments to my class is welcomed, since i'm new to .Net.

Regards /Snedker

Nov 21 '05 #3
On Fri, 19 Nov 2004 09:32:03 -0600, "Chris" <chris@No_Spam_Please.com>
wrote:
You need to do the download in a seperate thread from the form.

Dim DF as new DownloadFile Class
Dim t As System.Threading.Thread
t = New System.Threading.Thread(AddressOf DF.DownloadFile)
t.Start()

Now create a property in your DownloadFile class that returns the progress
amount. Do a loop in the form something like

Do While DF.CurrentProgressPercent < 100
'Update Progress Bar in here
'Now sleep for a short time
System.Threading.Thread.CurrentThread.Sleep(500) 'I think
that's close to the class that you need, don't have ide on this puter
Loop
'Close the thread
t.abort()


First of all, thx for your reply. I tried your suggestion - the code
works, but it still locks my application. I start the download, but it
is as if it doesn't reach my loop until the download has finished.

This is the code I have:

Dim l As Long
Dim t As System.Threading.Thread
t = New System.Threading.Thread(AddressOf df.DownloadFile)
t.Start()

'Timer1.Start()

df.FileDestination = "F:\administrations3.adp"
df.FileSource = "http://dbconsult.dk/AdministrationS3.adp"

l = df.getURLFileSize()

If l = 0 Then
MsgBox("Fil-størrelse kunne ikke findes")
Else
df.DownloadFile()
End If

Do While df.PercentCompleted < 100
System.Threading.Thread.Sleep(500)
Me.ListBox1.Items.Add(df.PercentCompleted)
Loop

t.Abort()
df = Nothing
Regards /Snedker
Nov 21 '05 #4
On Mon, 22 Nov 2004 10:09:19 -0000, "Nak" <a@a.com> wrote:
Well, I had actually sent you a link to the source of WTR, which
contains a reusable async download class. But maybe you didn't notice it,
so have this instead!


I didn't notice in the first place. Thanks - your help is greatly
appreciated (and made me understand better).

Also thanks to Chris for input and inspiration.

Regards /Snedker
Nov 21 '05 #5
On Mon, 22 Nov 2004 10:09:19 -0000, "Nak" <a@a.com> wrote:
Hi there,

Well, I had actually sent you a link to the source of WTR, which
contains a reusable async download class. But maybe you didn't notice it,
so have this instead!

Nick.


Just want to say that I've added

With pWrqRequest
.Proxy = WebProxy.GetDefaultProxy
.Proxy.Credentials = CredentialCache.DefaultCredentials()

to the dostart procedure. This helped me out with 403/407 error from
the ISA/proxy server.
Regards /Snedker
Nov 21 '05 #6
Nak
Hi there,

Aah, I hadn't even thought of proxy configuration, good idea, cheers for
sharing that! :-)

Nick.

"Morten Snedker" <morten_spammenot_ATdbconsult.dk> wrote in message
news:f7********************************@4ax.com...
On Mon, 22 Nov 2004 10:09:19 -0000, "Nak" <a@a.com> wrote:
Hi there,

Well, I had actually sent you a link to the source of WTR, which
contains a reusable async download class. But maybe you didn't notice it,
so have this instead!

Nick.


Just want to say that I've added

With pWrqRequest
.Proxy = WebProxy.GetDefaultProxy
.Proxy.Credentials = CredentialCache.DefaultCredentials()

to the dostart procedure. This helped me out with 403/407 error from
the ISA/proxy server.
Regards /Snedker

Nov 21 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: florian | last post by:
Hi, we have a contention problem because of an application which tries to insert a duplicate row in a table with primary key. This insert fails of course but the locks are not released within...
6
by: John Carroll | last post by:
Is there a SQL query that can be run against a database that will give me all the details on any locks that are in place at the given time? I am interested in find the lock type and owner. Thank...
0
by: Bruce Pullen | last post by:
DB2 v7.2 (FP7 - DB2 v7.1.0.68) on AIX 5.2.0.0. We're seeing unexpected single row (then commit) insert locking behaviour. We're seeing Applications that already hold row-level W locks in...
0
by: db2group88 | last post by:
hi, we are using db2 udb v8.1 on windows with type 4 db2jcc driver, our application use jdbc to create statement and execute query, i would like to know when the application connect to DB2 blow up...
6
by: A.M-SG | last post by:
Hi, I have an aspx page at the web server that provides PDF documents for smart client applications. Here is the code in aspx page that defines content type: Response.ContentType =...
8
by: DEWright_CA | last post by:
Why does WebClient.DownloadFile loose my completed path? Ok, I have a function in my app then when my button is clicked it checks to see if the files come from a local drive or a http address....
1
by: shenanwei | last post by:
I have db2 v8.2.5 on AIX V5.3 with all the switches on Buffer pool (DFT_MON_BUFPOOL) = ON Lock (DFT_MON_LOCK) = ON Sort ...
8
by: =?Utf-8?B?UnVpIE9saXZlaXJh?= | last post by:
WebClient.DownloadFile I am using the WebClient.DownloadFile function to download a file from server to a local client. When I execute the below code, file is created in server and not in...
4
by: Mateusz Mrozewski | last post by:
Hi, Is there a difference between: SELECT * FROM mytable WHERE somecolumn='Y' FOR UPDATE WITH RS and SELECT * FROM mytable WHERE somecolumn='Y' FOR UPDATE WITH RS USE AND KEEP UPDATE LOCKS I...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.