473,698 Members | 2,225 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.Downloa dFile(_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 1313
You need to do the download in a seperate thread from the form.

Dim DF as new DownloadFile Class
Dim t As System.Threadin g.Thread
t = New System.Threadin g.Thread(Addres sOf 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.CurrentProgr essPercent < 100
'Update Progress Bar in here
'Now sleep for a short time
System.Threadin g.Thread.Curren tThread.Sleep(5 00) '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_spammen ot_ATdbconsult. dk> wrote in message
news:sg******** *************** *********@4ax.c om...
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.Downloa dFile(_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_spammen ot_ATdbconsult. dk> wrote in message
news:sg******** *************** *********@4ax.c om...
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.Downloa dFile(_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.Threadin g.Thread
t = New System.Threadin g.Thread(Addres sOf 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.CurrentProgr essPercent < 100
'Update Progress Bar in here
'Now sleep for a short time
System.Threadin g.Thread.Curren tThread.Sleep(5 00) '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.Threadin g.Thread
t = New System.Threadin g.Thread(Addres sOf df.DownloadFile )
t.Start()

'Timer1.Start()

df.FileDestinat ion = "F:\administrat ions3.adp"
df.FileSource = "http://dbconsult.dk/AdministrationS 3.adp"

l = df.getURLFileSi ze()

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

Do While df.PercentCompl eted < 100
System.Threadin g.Thread.Sleep( 500)
Me.ListBox1.Ite ms.Add(df.Perce ntCompleted)
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.GetDef aultProxy
.Proxy.Credenti als = CredentialCache .DefaultCredent ials()

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_spammen ot_ATdbconsult. dk> wrote in message
news:f7******** *************** *********@4ax.c om...
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.GetDef aultProxy
.Proxy.Credenti als = CredentialCache .DefaultCredent ials()

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
5114
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 this transcation. Why DB2 does not release the X lock after a failed insert??? We use DB2 UDB EEE Version 7.2 Fixpak 9, but we also can reproduce the Problem on DB2 UDB ESE 8.1 Linux Fixpak 4.
6
20616
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 you, John
0
3379
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 lock-wait, waiting to acquire row-level X locks. The lock-waits are behind applications that have row-level X locks on different rows (honestly). Both executing and lock-waiting applications have been granted IX table locks.
0
1385
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 in the middle, will the resource created by this application get released from DB2, such as locks, when i do db2 get snapshot for locks for the application handler, i still can see the locks holding there, so why they are not released when the...
6
13291
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 = "application/octet-stream"; Response.AppendHeader("Content-Disposition", "attachment;filename=" + fileID.ToString() + ".pdf");
8
9011
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. The portion of the code that pulls from the drive works great, but when the http address is active it changes the originating path to my C:\Windows\System32 folder instead of the proper path. I keep the path as a field on my form so I am certain...
1
2890
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 (DFT_MON_SORT) = ON Statement (DFT_MON_STMT) = ON Table (DFT_MON_TABLE) = ON Timestamp (DFT_MON_TIMESTAMP) = ON Unit of work ...
8
9518
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 client. What am I doing wrong?
4
6348
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 have two transactions running concurrently which perform select on some table and try to update some column from the first result from the list. I want to prevent concurrent updates so only one transaction
0
8674
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9026
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8893
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8861
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7723
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
4619
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3045
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2328
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2001
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.