N
news.microsoft.com
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.LoadImageFromServer(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;
}
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.LoadImageFromServer(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;
}