473,385 Members | 1,356 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,385 software developers and data experts.

Please help on issue on httpRequest.

HI, I have the following code that runs in a thread, what the code does is
call a url, and read data from it. The main app need a way to terminate the
read anytime, and call the url again, which I use _reconnect to handle. The
loop will keep on reading data until the value of _reconnect set to true.
Then it will create a new connection and read again. There are two issues:

1, The readline doesn't return until it read a line, so before that, I can
not check _reconnect.

2, It seems I the release to request doesn't work well, even I terminate the
request and create a new one with WebRequest.Create, quite ofter it gaves
error says disposednetworkstream can not be used.

Any idea? please help!

Thanks!

while(!_disposed)
{
try
{
_reconnect = false;

HttpWebRequest request = (HttpWebRequest)WebRequest.Create(_url);
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
StreamReader reader = new StreamReader (response.GetResponseStream());

string line="", message="";
while(!_reconnect && !_disposed && (line=reader.ReadLine())!=null)
{
if(line.StartsWith("///LLIFT//"))
{
if(_onRelayMessage!=null && message!="")
{
_onRelayMessage(this,message);
message="";
}
}
else if(line!="")
message += line;
}

if(request!=null)
try
{
request.Abort();
}
catch
{
}
if(reader!=null)
reader.Close();
if(response!=null)
response.Close();
}
catch(Exception e)
{
string a=e.Message;
}
}
Oct 27 '05 #1
0 985

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

Similar topics

3
by: HikksNotAtHome | last post by:
In Mozilla 1.4b, when the URL is set to a local URL, it works as expected. function showIt(){ var xmlhttp = new XMLHttpRequest(); xmlhttp.open("GET", "blank.html" ,true);...
0
by: Bp | last post by:
I'm writing a simple HTTPRequest that retrieves the content of a web page. Dim httpReq As System.Net.HttpWebRequest Dim httpResp As System.Net.HttpWebResponse httpReq =...
1
by: Paul W | last post by:
I want to refer to server.machinename in a module (not code-behind a page). If I try: dim uu as string uu = System.Web.HttpServerUtility.MachineName I get a compile error "Reference to a...
0
by: davidw | last post by:
HI, I have the following code that runs in a thread, what the code does is call a url, and read data from it. The main app need a way to terminate the read anytime, and call the url again, which I...
1
by: Gunnar | last post by:
I am finding some unusual behavior with techniques I am using to show/hide/update data without having to refresh the page. I'm quite sure it's developer ignorance on my part and would be grateful...
3
by: jeremymcnitt | last post by:
Hi, I looked through the groups, and couldn't find what I was looking for, and was wondering if anyone here could help me out. I am newish to ASP.Net and was presented a problem that I don't know...
1
by: Jeff | last post by:
ASP.NET 2.0 I'm about to program a HttpRequest from my asp.net 2.0 website. I'll request another server using HttpRequest and ask if password etc are okay.... So I've looked into the...
4
by: Rootworker | last post by:
I have two simple web services, as shown below. One returns the file size of a test file, and the second the file itself. I can successfully recover the file size using the following code:\ ...
3
by: Joseph Geretz | last post by:
I'm using the Request Filter documentation which can be found here: http://msdn.microsoft.com/en-us/library/system.web.httprequest.filter.aspx In this example, two filters are installed, one...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

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.