473,939 Members | 9,021 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Stopping a WebClient.Downl oadData

Hi there!

Fisrt the question: there is a ay to make the DownloadData when I want?

I have a WebClient class
I use myWebClient.Dow nloadData(remot eUrl) to connect to internet server
All this in a separate thread for asincron pourpose
Anyway, when I try to close the application before DownloadData returned, it
wont stop this thread.

The thread run untill a bool variable is set..but if the thread is not on
Reset state I cant send the Set call, or, even if I call it, the Reset is
next

this is the running function for the thread:

Private Sub start()
Do While True
paused.WaitOne( ) 'wait on the pause event...
If isCancelled = True Then Exit Do
Try
Dim datas, sData As Byte()
Dim strData As String
'sData = getBytes()
SetHeaders()
datas = wbclient.Downlo adData(SERVER_A DDRESS)
'datas = wbclient.Upload Data(SERVER_ADD RESS, sData) ' signal
back to the caller that we're done...
strData = Encoding.ASCII. GetString(datas )
Dim responseHeaders As New WebHeaderCollec tion
responseHeaders = wbclient.Header s()

onResponse.Invo ke(datas)
paused.Reset() ' pause the thread...
Catch ex As WebException
onResponseError .Invoke(ex.Mess age)
paused.Reset() ' pause the thread...
End Try
Loop
End Sub
Nov 20 '05 #1
4 3697
Cor
Hi Crirus,
I did not look very in detail to your code, but I have the download in a
seperate thread and "abort" that thread in the situation, I thought, you did
describe and I thought it works (I never know with the webclient)..
Cor
Nov 20 '05 #2
I use a reset/set system to sleep the thread and a while loop.
As long as Cancel is false, the thread remain in while and sleep or run...
If I make Cancel=false then the while exit and the thread finish.

So, the ideea is that when the thread running routine wait for data in that
method, if I try to cancel the thread he is allredy running so no Cancel is
tested
"Cor" <no*@non.com> wrote in message
news:uH******** ******@TK2MSFTN GP12.phx.gbl...
Hi Crirus,
I did not look very in detail to your code, but I have the download in a
seperate thread and "abort" that thread in the situation, I thought, you did describe and I thought it works (I never know with the webclient)..
Cor

Nov 20 '05 #3
Cor
Hi Crirus,
That I did test to, all other methods, keep the thread alive, only the
abort did give me a solution. (It kills it in a way, but a thread is never
killed really direct by your program as far as I know, but it stops
downloading, I told I am not sure, but that is only a very little bit).
Cor
Nov 20 '05 #4
Solved...when DownloadData return I just kill the thread if Cancel is
true...usualy that delay hapend when webClient cant find the host
"Crirus" <Cr****@datagro up.ro> wrote in message
news:%2******** ********@TK2MSF TNGP11.phx.gbl. ..
Hi there!

Fisrt the question: there is a ay to make the DownloadData when I want?

I have a WebClient class
I use myWebClient.Dow nloadData(remot eUrl) to connect to internet server
All this in a separate thread for asincron pourpose
Anyway, when I try to close the application before DownloadData returned, it wont stop this thread.

The thread run untill a bool variable is set..but if the thread is not on
Reset state I cant send the Set call, or, even if I call it, the Reset is
next

this is the running function for the thread:

Private Sub start()
Do While True
paused.WaitOne( ) 'wait on the pause event...
If isCancelled = True Then Exit Do
Try
Dim datas, sData As Byte()
Dim strData As String
'sData = getBytes()
SetHeaders()
datas = wbclient.Downlo adData(SERVER_A DDRESS)
'datas = wbclient.Upload Data(SERVER_ADD RESS, sData) ' signal back to the caller that we're done...
strData = Encoding.ASCII. GetString(datas )
Dim responseHeaders As New WebHeaderCollec tion
responseHeaders = wbclient.Header s()

onResponse.Invo ke(datas)
paused.Reset() ' pause the thread...
Catch ex As WebException
onResponseError .Invoke(ex.Mess age)
paused.Reset() ' pause the thread...
End Try
Loop
End Sub

Nov 20 '05 #5

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

Similar topics

2
4690
by: Gary Short | last post by:
Hello group, I was wondering if anyone here could help me with an odd WebClient problem. When I run the following code: WebClient aWebClient = new WebClient(); Byte aBA = aWebClient.DownloadData("http://www.microsoft.com"); string strContent = Encoding.ASCII.GetString(aBA); Everything works as expected. However, when I run the following code:
1
3267
by: yyy | last post by:
This problem bothers me for a long time: I use WebClient.DownloadData in order to read text from an HTML document this way: WebClient c = new WebClient(); string html= ASCIIEncoding.Default.GetString(c.DownloadData("http://www.test.com")); When I run the code, I get this error message after a few seconds:
1
2813
by: ATS | last post by:
ERR - WebClient.DownloadData returns "protocol violation" Please help, I'm getting a "protocol violation" from a site that is working perfectly fine when I issue WebClient.DownloadData as such: WebClient WebClient_Temp = new WebClient(); byte zbyteTemp = WebClient_Temp.DownloadData (
1
1346
by: YA | last post by:
I am using WebClient to download a text file from the net every 2 minutes. The problem is that I think I am reading the file from cache since when the file is change I still get the old file. Here is my code: Dim myWebClient As New WebClient() Dim responseArray As Byte() = myWebClient.DownloadData(szURL) How can I tell WebClient not to use cache ? Thanks in advance
2
4907
by: Rags | last post by:
Hi We are creating a web application using .NET which renders some reports. The reports are created in MS Reporting Services and can be accessed by typing in a URL with the required parameters in a browser. The reports are getting rendered fine if I type the URL in the browser. Within the web application, however, we are using the webclient.downloaddata method to extract the HTML by specifying the URL and rendering within the .NET...
8
9057
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
3125
by: Scampi | last post by:
Hi, I've been working on an application to do some 'scraping' of web content, using the WebClient class. I'm using code rather like the following.. Dim objWebClient As New WebClient Dim strURL As String = CType(URL, String) Dim aRequestedHTML() As Byte Dim objUTF8 As New UTF8Encoding
0
1508
by: Ron | last post by:
Hi. I have a webserver which executes the following code: m_webclient = New WebClient Dim byteArray As Byte() byteArray = m_webclient.DownloadData(url) This actually retrieves an XML document which I parse. This code works perfectly, up to now. However, we recently installed SSL on the web server (a Unix box) and
1
1789
by: jmk | last post by:
I'm trying to use an external SMS-service through .NET Framework 1.1 and using the webClient.DownloadData(strMessage) method. The strMessage is a string consisting the parameters to send a message, and the return-value to the DownloadData method is to be a status code for the requested message. However, using this method causes a connection-timeout from the SMS-service. Sending the same strMessage using reponse.redirect(strMessage) sends...
0
10134
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
9963
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
11524
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...
0
10659
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...
1
8218
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
7386
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
6076
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
6297
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
4447
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.