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

  • SEARCH
  • Home
  • 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 8134697
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T10:07:41+00:00 2026-06-06T10:07:41+00:00

There is something that I really don’t understand with the HttpListener. The code below

  • 0

There is something that I really don’t understand with the HttpListener.

The code below speaks for itself and expose the “issue” in one way.

I simply instantiate two different HttpListener with the same single prefix for each one.
I then start the first listener, and of course I get an HttpListenerException when I try to start the second one (same prefix) .. so far so good.

Ok my fault (or the end user fault if we are going through a configuration tool). No panic, I will just clear the prefix of the second listener and specify a new one … or stop the first listener and try to restart the second one, or whatever …

But can’t do all of this because as soon as I am trying to access the second listener Prefixes or anything else, I get an ObjectDisposedException (Cannot access a disposed object. Object name: ‘System.Net.HttpListener’).

My question is WHY ?
I do not see anything in HttpListener documentation specifying that on a HttpListenerException some inner stuff of HttpListener object is somehow disposed and the object is just useless from that point on …

So this means that if I am starting an HttpListener and get an HttpListenerException I have to recreate a whole new HttpListener object in any case ? Seems a little bit weird for me (but there may be another way or a very good reason).

Thanks in advance for your answers !!

var listener1 = new HttpListener();
listener1.Prefixes.Add("http://localhost:8080/MyHandler/");
listener1.Start();

var listener2 = new HttpListener();
listener2.Prefixes.Add("http://localhost:8080/MyHandler/");

try
{
   listener2.Start();
}
catch (HttpListenerException ex)
{
  listener2.Prefixes.Clear(); // BAM ! ObjectDisposedException
}
  • 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-06-06T10:07:42+00:00Added an answer on June 6, 2026 at 10:07 am

    An exception means something has gone horribly wrong. Rather than allow unsuspecting consumers to continue to use a possibly corrupt and unstable object, it instead disposes of itself. Just create the new listener, and be happy that you don’t have to worry about using a possibly useless object.

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

Sidebar

Related Questions

I'm beginning and there is something that I don't understand with pointers. I have
math.h is not really a documentation. Is there something else that will describe these
cgi.escape seems like one possible choice. Does it work well? Is there something that
I am using the CodeIgniter DataMapper ORM, but there is something that I don't
I don't get it: An URL is something that really locates a ressource, i.e.
there is something that I miss about the cc-NUMA architecture and the need to
If there's something that everybody hates about Magento it's endlessly configuring your modules before
I am playing with the .net remoting features and there is something that I
I am trying some things with JSON and PHP and there is something that
I am playing a bit with fork/vfork functions, and there is something that is

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.