Wednesday, February 4, 2009

C# HttpListener: HttpListenerException: The I/O operation has been aborted because of either a thread exit or an application request

In this blog, I'm going to start focusing more on small details of C# programming. With this said:

 

HttpListener is a great C# 2.0 class. It allows you to create web-servers without having to have an IIS server on your machine. This became possible since a while ago, IIS was divided into two parts: HTTP.SYS and proper IIS. HTTP.SYS is supplied with any machine running XP SP2 or Server 2003. HttpListener allows .net programs to use HTTP.sys

My program creates HTTPListener, calls Start and BeginGetContext methods. Then, the thread terminates. Whenever an HTTP request is received a delegate is called on a thread pool thread which call EndGetContext and generates HTTP request. It worked fine on Vista, but started throwing exceptions on Server 2003. After I made sure that the thread calling HTTPLIstener.Start didn't terminate, the exception went away.

I hope, this will be useful to some pure soul trying to debug.

3 comments:

ChocolateValley said...

Please can you pure more info here?
i have a httpListener that listens to a port.
now i get this ____ exception
The I/O operation has been aborted because of either a thread exit or an application request

any help will be more than welcome
nirniron

Katulus said...

Thank you for this post! It solved my issue in 5 minutes. Without it I bet I would spend hours with debugging and trying to fix it.

Anonymous said...

Thanks a lot! Fixed our problem in minutes!