Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3980988
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T05:21:22+00:00 2026-05-20T05:21:22+00:00

I’m getting a terrible exception thrown and IDK what to do to fix it

  • 0

I’m getting a terrible exception thrown and IDK what to do to fix it 🙁

System.ObjectDisposedException 
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.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()

I’ve read that this occurs when you try and reuse an HttpWebRequest or something like that, but I’ve double and triple checked the whole project and I’m not reusing any HttpWebRequest

I am downloading HTML on a separate thread, and sometimes I need to abort that thread, but I call Join so that shouldn’t be a big issue right?

Is there any way to catch this Exception or have it not be thrown? Or is there any way I can find exactly where it is been thrown from (which instance of HttpWebRequest or what ever object throws this)

EDIT:

Ok, a little more about what’s going on. I’m making HttpWebRequest calls on separate threads off the UI (like most people) but when I close the application, it hangs because the HTTP requests haven’t succeeded or timed out. So I decided to Abort them (such a violent word, don’t you think?) Thats when the exceptions started happening. If there is a better way to do it, i’m all ears!

Here is one of the methods that I’m calling that sometimes gets interrupted. I run this until there are at most 6 threads:

private static void startImageDownloading()
{
    ThreadStart start = () =>
    {
        while (_list.Count > 0) // _list contains all of the images that need to be downloaded
        {
            ImageRequest req; // ImageRequests are containers that hold all the request info
            lock (_list)
            {
                if (_list.Count > 0)
                    req = _list.Dequeue();
                else continue;
            }

            if (req.Item.Parent.IsDisposed)
                continue;

            using (MemoryStream i = getImageWeb(req))
                if (i != null)
                {
                    foreach (var callback in req.Callbacks)
                        callback(i);    //  Callbacks is a List<ImageDelegate> object

                    if (req.Item.Parent != null && !req.Item.Parent.IsDisposed)
                        req.Item.Parent.Damage();   //  Cross thread Invalidate call
                }
        }

        Thread.CurrentThread.Priority = ThreadPriority.Lowest;
    };

    Thread t = new Thread(start) { IsBackground = true, Priority = ThreadPriority.BelowNormal };

    t.Start();

    _downloadThreads.Add(t);
}

Here is the getImageWeb:

private static MemoryStream getImageWeb(ImageRequest req)
{
    int tries = 0;
    try
    {
        MemoryStream ret = null;
        while (tries < maxRetries && (ret = downloadImageFile(req.Uri)) == null && !req.Cancelled)
            tries++;

        return ret;
    }
    catch { }

    return null;
}

And finally downloadImageFile:

private static MemoryStream downloadImageFile(string url)
{
    MemoryStream ret = null;

    try
    {
        var uri = new Uri(url);

        var webRequest = (HttpWebRequest)WebRequest.Create(uri);
        webRequest.Method = "GET";
        webRequest.Timeout = 10000;
        webRequest.ProtocolVersion = HttpVersion.Version10;
        webRequest.Proxy = null;
        using (var webResponse = (HttpWebResponse)webRequest.GetResponse())
        {
            if (webResponse.StatusCode.ToString().Equals("OK"))
            {
                ret = new MemoryStream();
                using (Stream responseStream = webResponse.GetResponseStream())
                {
                    if (responseStream == null)
                        return null;
                    CopyStream(responseStream, ret);
                }
                ret.Position = 0;
            }
        }
    }
    catch (WebException e)
    {
        string error = "";
        if (e.Response != null)
            using (var response = e.Response)
            using (var resp = response.GetResponseStream())
            using (var errorStream = new StreamReader(resp))
                error = errorStream.ReadToEnd();
    }
    catch (Exception exp)
    {
    }

    return ret;
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T05:21:22+00:00Added an answer on May 20, 2026 at 5:21 am

    Aborting a thread causes any [non-shared] referenced objects to be disposed automatically (if IDisposable is implemented by that object). There’s a timer which is configured to do something in intervals (it seems some async network activity). Aboting the thread caused that timer to be disposed and this is the reason for exception.

    Try to call appropriate disconnecting method instead of aborting the thread. As a general rule never abort a thread unless you are sure where it is and what’s the consequences of stopping it from finishing his job. More details is needed for talking more precise about your case.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
I have a JSP page retrieving data and when single or double quotes are
Seemingly simple, but I cannot find anything relevant on the web. What is the
Does anyone know how can I replace this 2 symbol below from the string
this is what i have right now Drawing an RSS feed into the php,
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.