I think, this is familiar to any Windows developer: you start a remote debug monitor, point your VS to it and all you get is some network error message box. Today, I finally solved this mystery. Make sure that you can access the machine running Visual Studio from the machine where the program is running by its DNS name. In my case, I just got assigned a new IP address from DHCP and the remote machine had a wrong IP for my machine. Once I fixed this, remote debugging started working again.
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.