Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Exception: The operation has timed-out.

Reply
Thread Tools

Exception: The operation has timed-out.

 
 
news.microsoft.com
Guest
Posts: n/a
 
      10-28-2005
I experienced the following exception occasionally when the program
downloads the image from the Web site. Who can give me some solution for it?
Thanks in advance.


----------
Exception:
Message: The operation has timed-out.
Source: System
TargetSite: Int32 Read(Byte[], Int32, Int32)
StackTrace:
at System.Net.ConnectStream.Read(Byte[] buffer, Int32 offset, Int32
size)
at RTC7.ImageSystem.ViewPictureInRecord.Copy(Stream stream, String
filename)
at RTC7.ImageSystem.ViewPictureInRecord.LoadImageFrom Server(String sUrl),


//-------------
// Codes:
public string LoadImageFromServer(string sUrl)
{
bool isAborted = false;
string strURL_ = sUrl; //this.GetUrlOfPicture();
string strLocalTmpFile = "";
Stream stream = null;
WebRequest webreq = null;
WebResponse webres = null;
try
{
Uri uri = new Uri(strURL_);

webreq = WebRequest.CreateDefault(uri);

webreq.Timeout = 60000;
webres = webreq.GetResponse();

if(webres != null)
stream = webres.GetResponseStream();
else
return null;
//...
}
catch(Exception ex)
{
// ...
}
finally
{
if(webres != null)
webres.Close();
if(stream != null)
stream.Close();
}
return strLocalTmpFile;
}

public bool Copy(Stream stream, string filename)
{
const int conBufferLeng = 20000;
FileStream fstream= null;
byte[] buffer = new byte[conBufferLeng];
int iByteCountInBuffer = conBufferLeng;
bool blnOkay = false;
try
{
if(stream != null)
{
if(File.Exists(filename) == false)
fstream = File.Create(filename);
else
fstream = File.OpenWrite(filename);
if(fstream != null && fstream.CanWrite == true)
{
if(stream.CanSeek == true)
stream.Position = 0;
do
{
lock(this.syncObject)
iByteCountInBuffer = stream.Read(buffer,0,conBufferLeng);
fstream.Write(buffer,0,iByteCountInBuffer);
}
while(iByteCountInBuffer > 0); //conBufferLeng);
blnOkay = true;
} // If destination is okay.
} // If source is okay.
}
finally
{
if(fstream != null)
fstream.Close();
buffer = null;
}
return blnOkay;
}




 
Reply With Quote
 
 
 
 
Kevin Spencer
Guest
Posts: n/a
 
      10-28-2005
Try again?
Show the user a message?

You have an external dependency. You are attempting to download an image
from a location you have no control over. It is a network resource. If the
operation times out, the response took longer than the 60 seconds you
instructed the WebRequest to wait for. Perhaps the image is way large.
Perhaps the server quit responding. Perhaps a packet was dropped. Maybe some
guy in a car ran into the wrong telephone pole. Who knows? It's an external
dependency. You have to handle this sort of contingency. How you handle it
is your requirement to decide.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
A watched clock never boils.

"news.microsoft.com" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
>I experienced the following exception occasionally when the program
> downloads the image from the Web site. Who can give me some solution for
> it?
> Thanks in advance.
>
>
> ----------
> Exception:
> Message: The operation has timed-out.
> Source: System
> TargetSite: Int32 Read(Byte[], Int32, Int32)
> StackTrace:
> at System.Net.ConnectStream.Read(Byte[] buffer, Int32 offset, Int32
> size)
> at RTC7.ImageSystem.ViewPictureInRecord.Copy(Stream stream, String
> filename)
> at RTC7.ImageSystem.ViewPictureInRecord.LoadImageFrom Server(String
> sUrl),
>
>
> //-------------
> // Codes:
> public string LoadImageFromServer(string sUrl)
> {
> bool isAborted = false;
> string strURL_ = sUrl; //this.GetUrlOfPicture();
> string strLocalTmpFile = "";
> Stream stream = null;
> WebRequest webreq = null;
> WebResponse webres = null;
> try
> {
> Uri uri = new Uri(strURL_);
>
> webreq = WebRequest.CreateDefault(uri);
>
> webreq.Timeout = 60000;
> webres = webreq.GetResponse();
>
> if(webres != null)
> stream = webres.GetResponseStream();
> else
> return null;
> //...
> }
> catch(Exception ex)
> {
> // ...
> }
> finally
> {
> if(webres != null)
> webres.Close();
> if(stream != null)
> stream.Close();
> }
> return strLocalTmpFile;
> }
>
> public bool Copy(Stream stream, string filename)
> {
> const int conBufferLeng = 20000;
> FileStream fstream= null;
> byte[] buffer = new byte[conBufferLeng];
> int iByteCountInBuffer = conBufferLeng;
> bool blnOkay = false;
> try
> {
> if(stream != null)
> {
> if(File.Exists(filename) == false)
> fstream = File.Create(filename);
> else
> fstream = File.OpenWrite(filename);
> if(fstream != null && fstream.CanWrite == true)
> {
> if(stream.CanSeek == true)
> stream.Position = 0;
> do
> {
> lock(this.syncObject)
> iByteCountInBuffer = stream.Read(buffer,0,conBufferLeng);
> fstream.Write(buffer,0,iByteCountInBuffer);
> }
> while(iByteCountInBuffer > 0); //conBufferLeng);
> blnOkay = true;
> } // If destination is okay.
> } // If source is okay.
> }
> finally
> {
> if(fstream != null)
> fstream.Close();
> buffer = null;
> }
> return blnOkay;
> }
>
>
>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Boolean operation and arithmetic operation Buzz Lightyear C++ 10 08-12-2009 01:27 PM
I/O operation, file operation behaviou raan C++ 2 08-16-2007 07:13 PM
Does bit operation always work more efficiently than math operation? david ullua C Programming 13 03-01-2006 11:02 PM
Operation has timed out in ASP.Net Application =?Utf-8?B?S2h1cnJhbSBJc2hmYXEgUmF0aG9y?= ASP .Net 0 09-02-2004 07:33 AM
[WebException: The operation has timed-out.] Matt ASP .Net 0 01-10-2004 02:26 PM



Advertisments