Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > C# and C > C# 2008 > C# 2008 aka C# 3.0
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
C# 2008 aka C# 3.0 Discuss the Visual C# 2008 (aka C# 3.0) language
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C# 2008 aka C# 3.0 section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
 
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old August 13th, 2009, 03:33 PM
Registered User
 
Join Date: Jul 2009
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default HttpListener Issue

I am threading an HttpListener application and running into an exception when stopping the listener.

The I/O operation has been aborted because of either a thread exit or an application request.

The error code is 995. I am not sure what I am doing wrong but could sure use some assistance.

using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Linq;
using System.Text;
using System.Net;
using System.Threading;


namespace CSG.CentricInterfaces.Emulator
{
public class EmulatorServer
{
//
// Declare the listener variables.
//
HttpListener _emulatorListener;
HttpListenerContext _emulatorContext;

//
// Thread variables.
Thread _emulatorListenerThread;
string _emulatorName = string.Empty;

//
// Declare class variables.
//
string _hostPort = string.Empty;

/// <summary>
/// Default constructor that will use the localhost and port 2112
/// for the prefix arguments.
/// </summary>
public EmulatorServer()
{
//
// Default host port for Centric Interfaces emulator(s).
//
_hostPort = "http://localhost:6111/";
_emulatorName = "CentricInterfacesEmulator";

}

/// <summary>
/// Overloaded constructor that takes the host and port as
/// parameters.
/// </summary>
/// <param name="HostPort"></param>
public EmulatorServer(string HostPort, string EmulatorName)
{
//
// Set the object variable to be used.
//
_hostPort = HostPort;
_emulatorName = EmulatorName;
}

/// <summary>
///
/// </summary>
public void Start()
{
_emulatorListenerThread = new Thread(EmulatorListenerThread);
_emulatorListenerThread.Name = _emulatorName;

_emulatorListenerThread.Start();
}

/// <summary>
/// Stop the listener so GC can clean up the resources.
/// </summary>
public void Stop()
{
//
// Cleanup the listener.
//
_emulatorListener.Stop();
}

/// <summary>
///
/// </summary>
protected void EmulatorListenerThread()
{
try
{
//
// Instantiate and initialize the listener.
//
_emulatorListener = new HttpListener();

//
// Add the host and port to the prefix list.
//
_emulatorListener.Prefixes.Add(_hostPort);

//
// Start the listener.
//
_emulatorListener.Start();

//
// Setup recursive port monitoring.
//
while (true)
{
//
// Listen for the next incoming message.
//
_emulatorContext = _emulatorListener.GetContext();
}
}
catch (Exception e)
{
Console.WriteLine("Exception message: {0}", e.Message);
}
}
}
}
 


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
HTTPListener Exception and 404 Not Found error JanK .NET Web Services 0 June 2nd, 2006 03:56 AM
CDATA issue sgruhier XSLT 0 February 20th, 2005 03:28 AM
Another issue islandtiu BOOK: Beginning ASP 3.0 1 February 14th, 2005 11:49 AM
Sub report issue kondapally Crystal Reports 2 February 9th, 2005 11:35 AM
Concurrency Issue billy_bob_the_3rd Classic ASP Components 1 October 23rd, 2004 09:33 AM



All times are GMT -4. The time now is 11:56 AM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.