473,830 Members | 2,272 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 3686
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
4686
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
3261
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
2805
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
1328
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
4900
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
9038
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
3120
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
1500
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
1782
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
9790
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
9642
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
10481
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
10524
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
10199
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
9312
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
5616
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...
1
4409
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
3
3074
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.