Raise event from http listener (Async listener handler)

Posted by Sean on Stack Overflow See other posts from Stack Overflow or by Sean
Published on 2009-11-13T17:57:16Z Indexed on 2010/05/01 9:07 UTC
Read the original article Hit count: 370

Hello, I have created an simple web server, leveraging .NET HttpListener class. I am using ThreadPool.QueueUserWorkItem() to spawn a thread to listen to incoming requests. Threaded method uses HttpListener.BeginGetContext(callback, listener), and in callback method I resume with HttpListener.EndGetContext() as well as raise an even to notify UI that listener received data. This is the question - how to raise that event?

Initially I used ThreadPool:

ThreadPool.QueueUserWorkItem(state => ReceivedRequest(httpListenerContext, receivedRequestArgs));

But then started to doubt, maybe it should be a dedicated thread (as appose to waiting for a thread from pool):

new Thread(() => ReceivedRequest(httpListenerContext, receivedRequestArgs)).Start();

Thoughts? 10X

© Stack Overflow or respective owner

Related posts about .NET

Related posts about multithreading