PC Review


Reply
Thread Tools Rate Thread

DownloadFile locks application

 
 
Morten Snedker
Guest
Posts: n/a
 
      19th Nov 2004
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
 
Reply With Quote
 
 
 
 
Chris
Guest
Posts: n/a
 
      19th Nov 2004
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:(E-Mail Removed)...
>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



 
Reply With Quote
 
Nak
Guest
Posts: n/a
 
      19th Nov 2004
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:(E-Mail Removed)...
>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



 
Reply With Quote
 
Morten Snedker
Guest
Posts: n/a
 
      22nd Nov 2004
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
 
Reply With Quote
 
Morten Snedker
Guest
Posts: n/a
 
      22nd Nov 2004
On Mon, 22 Nov 2004 10:09:19 -0000, "Nak" <(E-Mail Removed)> 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
 
Reply With Quote
 
Morten Snedker
Guest
Posts: n/a
 
      25th Nov 2004
On Mon, 22 Nov 2004 10:09:19 -0000, "Nak" <(E-Mail Removed)> 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
 
Reply With Quote
 
Nak
Guest
Posts: n/a
 
      25th Nov 2004
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:(E-Mail Removed)...
> On Mon, 22 Nov 2004 10:09:19 -0000, "Nak" <(E-Mail Removed)> 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



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Locks Cylinders Deadbolt Schlage, Medeco Mul-T-Locks, Baldwin Locks,Kwikset Locks, Mortise Locks, Dexter Locks lifeine Microsoft C# .NET 0 13th Oct 2009 06:46 PM
DataGridView locks up application Tony K Microsoft VB .NET 0 6th May 2008 12:32 AM
Computer locks when an application is waiting =?Utf-8?B?bWFyY2Vsc3dpZXR6YQ==?= Windows XP General 1 5th Nov 2007 08:31 PM
application pool locks file =?Utf-8?B?U3RldmUgQnVnZGVu?= Microsoft ASP .NET 2 10th Apr 2006 12:16 PM
MessageBox.Show Sometimes Locks my application Myron Marston Microsoft Dot NET Compact Framework 6 1st Aug 2005 05:03 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 12:14 AM.