Random Application Crash Problem

E

Erphan

Hi,

I am creating a simple WebRequest to access a web address. working great but
when i restart the device and lunch my application and initiate that web
request it halts or sumtimes it doesn't.

THIS HAPPENS WHEN THERE IS NO CONNECTION TO INTERNET IS AVAILABLE. ( No
Wifi, No GPRS/EDGE, No ActiveSync)


Language: C#
..NET Framework: 1.0 CF
Device: HTC S710
OS Ver: Windows Mobile 6 Standard


Code:

public static bool GetHTTPData(string strVal, out string strReturn)
{
strReturn = "";
Cursor.Current = Cursors.WaitCursor;
try
{
HttpWebRequest req =
(HttpWebRequest)HttpWebRequest.Create(strVal);
req.Method = "GET";
req.Timeout = 30000;
WebResponse resp = req.GetResponse();
StreamReader read = new
StreamReader(resp.GetResponseStream());
strReturn = read.ReadToEnd();
read.Close();
resp.Close();
req.Abort();
req = null;
}
catch (WebException we)
{
Cursor.Current = Cursors.Default;
MessageBox.Show(Constants.Lang.ConnectionGenericException,
Constants.Lang.ConnectionFailed, MessageBoxButtons.OK,
MessageBoxIcon.Asterisk, MessageBoxDefaultButton.Button1);
return false;
}
catch (Exception ex)
{
System.Windows.Forms.Cursor.Current = Cursors.Default;
MessageBox.Show(Constants.Lang.ConnectionGenericException,
Constants.Lang.ConnectionFailed, MessageBoxButtons.OK,
MessageBoxIcon.Asterisk, MessageBoxDefaultButton.Button1);
return false;
}
finally
{
Cursor.Current = Cursors.Default;
}
return true;
}
 
C

Chris Tacke, eMVP

Well you should be doing it async, so in a background thread or something.
That would at least keep your app responsive for the 30 seconds.


--

Chris Tacke, Embedded MVP
OpenNETCF Consulting
Giving back to the embedded community
http://community.OpenNETCF.com
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top