locked
ObjectDisposedException on Windows Mobile 6.1 Device RRS feed

  • Question

  • I am getting the following error on a windows mobile 6.1 professional device.

    GPSTrackerWM3.exe
    ObjectDisposedException

    at system.Threading.timer.throwifdisposed()
    at system.Threading.timer.change(UInt32 duetime, UInt32 period)
    at system.Threading.timer.change(Int32 duetime, Int32 period)
    at system.Net.HttpWebRequest.startReadWriteTimer()
    at system.Net.HttpWebRequest.ConnectionClient.Read (Byte[ ] data, Int32 offset, Int32 length)
    at system.Net.HttpReadStream.NetworkRead(Byte[ ] data, Int32 offset,Int32 length)
    at system.Net.ContentLengthReadStream.doRead(Byte [ ]  data, Int32 offset, Int32 length)
    at system.Net.HttpReadStream.ReadToDrain(Byte [ ] buffer, Int32 offset, Int32 length)
    at system.Net.HttpReadStream.doClose()
    at system.Net.ContentLengthReadStream.doClose()
    at system.Net.HttpReadStream.Finalize()

    Here is my source code:

    private string updateServer(string url) {
                StringBuilder sb = new StringBuilder();
                string message = "";

                try {
                    HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
                    HttpWebResponse response = (HttpWebResponse)request.GetResponse();
                    StreamReader reader = new StreamReader(response.GetResponseStream());
                    sb.Append(reader.ReadLine());
                    while (reader.ReadLine() != null) {
                        sb.Append(reader.ReadLine());
                    }
                    message = sb.ToString();

                    reader.Close();
                    response.Close();
                }
                catch (Exception e) {
                    Log.writeToLogFile("updateServer error:");
                    Log.writeToLogFile(url);
                    Log.writeToLogFile(e.Message);
                }

                return message;
            }

    thanks for your help
    Nick
    Friday, August 14, 2009 11:39 PM

Answers

  • Hi,

    Something to note, the code you provided is going to be misssing a ReadLine output :-

     while (reader.ReadLine() != null) {
                        sb.Append(reader.ReadLine());

    With the ReadLine method the "cursor" is going to progress therefore you are going to miss one of the ReadLine each time the while loops.

    I think this code should look something like this :-

    string lineRead = string.Empty;

     while ((lineRead = reader.ReadLine()) != null) {
                        sb.Append(lineRead);

    Hope this helps.

    Paul Diston
    http://www.smartmobiledevice.co.uk/
    Saturday, August 15, 2009 1:29 AM

All replies

  • Hi,

    Which line in the provided source code is the exception occurring?

    Thanks

    Paul Diston
    http://www.smartmobiledevice.co.uk/
    Saturday, August 15, 2009 1:21 AM
  • It's not clear to me. I am in Seattle and have not been able to generate this error on my cell. My client in Brazil is the one who has this problem. This error is actually shutting down the application on his cell phone.

    Nick

    I found this thread and I'm investigating that right now:

    http://social.msdn.microsoft.com/Forums/en-US/netfxcompact/thread/65ad4e2a-de0b-4a2d-bec3-6ccad26da0c7


    Saturday, August 15, 2009 1:23 AM
  • Hi,

    Something to note, the code you provided is going to be misssing a ReadLine output :-

     while (reader.ReadLine() != null) {
                        sb.Append(reader.ReadLine());

    With the ReadLine method the "cursor" is going to progress therefore you are going to miss one of the ReadLine each time the while loops.

    I think this code should look something like this :-

    string lineRead = string.Empty;

     while ((lineRead = reader.ReadLine()) != null) {
                        sb.Append(lineRead);

    Hope this helps.

    Paul Diston
    http://www.smartmobiledevice.co.uk/
    Saturday, August 15, 2009 1:29 AM
  • Good call, thanks Paul...

    Nick
    Saturday, August 15, 2009 1:31 AM