473,394 Members | 2,071 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Stopping a WebClient.DownloadData

Hi there!

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

I have a WebClient class
I use myWebClient.DownloadData(remoteUrl) 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.DownloadData(SERVER_ADDRESS)
'datas = wbclient.UploadData(SERVER_ADDRESS, sData) ' signal
back to the caller that we're done...
strData = Encoding.ASCII.GetString(datas)
Dim responseHeaders As New WebHeaderCollection
responseHeaders = wbclient.Headers()

onResponse.Invoke(datas)
paused.Reset() ' pause the thread...
Catch ex As WebException
onResponseError.Invoke(ex.Message)
paused.Reset() ' pause the thread...
End Try
Loop
End Sub
Nov 20 '05 #1
4 3661
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**************@TK2MSFTNGP12.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****@datagroup.ro> wrote in message
news:%2****************@TK2MSFTNGP11.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.DownloadData(remoteUrl) 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.DownloadData(SERVER_ADDRESS)
'datas = wbclient.UploadData(SERVER_ADDRESS, sData) ' signal back to the caller that we're done...
strData = Encoding.ASCII.GetString(datas)
Dim responseHeaders As New WebHeaderCollection
responseHeaders = wbclient.Headers()

onResponse.Invoke(datas)
paused.Reset() ' pause the thread...
Catch ex As WebException
onResponseError.Invoke(ex.Message)
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
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 =...
1
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=...
1
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...
1
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...
2
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...
8
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....
1
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...
0
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...
1
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,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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,...
0
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...
0
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...

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.