Wrox Programmer Forums
|
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 software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
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);
}
}
}
}





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





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.