473,799 Members | 3,132 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 1318
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
5129
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
20630
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
3389
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
1390
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
13305
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
9026
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
2895
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
9530
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
6353
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
9538
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10470
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10214
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
10023
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
9067
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...
1
7561
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5459
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5583
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2935
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.