473,406 Members | 2,698 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,406 software developers and data experts.

Exception: The operation has timed-out.

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;
}


Nov 19 '05 #1
1 3143
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" <ye******@sina.com> wrote in message
news:uF**************@TK2MSFTNGP10.phx.gbl...
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;
}

Nov 19 '05 #2

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

Similar topics

1
by: Todd A. Anderson | last post by:
Hi, I want to call VirtualProtect with the PAGE_GUARD flag to cause subsequent accesses to certain regions of memory to generate the STATUS_GUARD_PAGE exception. When this exception happens, I...
2
by: TS | last post by:
i'm wondering if it is preferred practice to throw exception in this circumstance. I have seen it done like that, but i have also read that you should try to never throw an exception in...
2
by: Javaman59 | last post by:
I have a GUI which is monitoring a real-time device. I have several timed actions, such as periodic polling of the device, and indicators which flash for a fixed period. My first implementation...
9
by: John Stemper | last post by:
I've recently moved an ASP.Net app to our deployment server after it was verified on our integration test server. On the deployment server I am now getting the following error:...
6
by: Pieter | last post by:
Hi, For some procedures that throws exceptions, I would like to show different messages to the user depending on what type of exception he's getting. For instance this one: when the file is...
24
by: Earl | last post by:
I have all of my data operations in a separate library, so I'm looking for what might be termed "best practices" on a return type from those classes. For example, let's say I send an update from...
132
by: Zorro | last post by:
The simplicity of stack unraveling of C++ is not without defective consequences. The following article points to C++ examples showing the defects. An engineer aware of defects can avoid...
0
by: Pieter | last post by:
Hi, When using clickOnce for a VB.NET 2.0 application it installs fine on every computer, except one (a new one...). Every is isstalled, Framework, Mdac, .... The error in the log file is:...
3
by: masood.iqbal | last post by:
In all the sample code snippets of try-catch code blocks that I have seen, the catch block does one of the following three things: 1). exits the program (after spitting out a cerr message) 2). ...
2
by: senglory | last post by:
My WCF: public interface IWorkbookService { DataTable GetDownpayments(KeyValuePair<int, string> sgm); } class WorkbookService : IWorkbookService
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...
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
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...
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
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...
0
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,...

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.