Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7181643
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T17:36:02+00:00 2026-05-28T17:36:02+00:00

I have a .NET Windows Service which spawns a thread that basically just acts

  • 0

I have a .NET Windows Service which spawns a thread that basically just acts as an HttpListener. This is working fine in synchronous mode example…

private void CreateLListener()
{
    HttpListenerContext context = null;
    HttpListener listener = new HttpListener();
    bool listen = true;

    while(listen)
    {
        try
        {
            context = listener.GetContext();
        }
        catch (...)
        {
            listen = false;
        }
        // process request and make response
    }
}

The problem I now have is I need this to work with multiple requests and have them responded to simultaneously or at least in an overlapped way.

To explain further – the client is a media player app which starts by making a request for a media file with the request header property Range bytes=0-. As far as I can tell it does this to work out what the media container is.

After it has read a ‘chunk’ (or if it has read enough to ascertain media type) it then makes another request (from a different client socket number) with Range bytes=X-Y. In this case Y is the Content-Length returned in the first response and X is 250000 bytes less than that (discovered using IIS as a test). At this stage it is getting the last ‘chunk’ to see if it can get a media time-stamp to gauge length.

Having read that, it makes another request with Range bytes=0- (from another socket number) to start streaming the media file properly.

At any time though, if the user of the client performs a ‘skip’ operation it then sends another request (from yet another socket number) with Range bytes=Z- where Z is the position to jump to in the media file.

I’m not very good with HTTP stuff but as far as I can tell I need to use multiple threads to handle each request/response while allowing the original HttpListener to return to listening. I’ve done plenty of searching but can’t find a model which seems to fit.

EDIT:

Acknowledgement and gratitude to Rick Strahl for the following example which I was able to adapt to suit my needs…

Add a Web Server to your .NET 2.0 app with a few lines of code

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T17:36:03+00:00Added an answer on May 28, 2026 at 5:36 pm

    If you need a more simple alternative to BeginGetContext, you can merely queue jobs in ThreadPool, instead of executing them on the main thread. Like such:

    private void CreateLListener() {
        //....
        while(true) {
            ThreadPool.QueueUserWorkItem(Process, listener.GetContext());    
        }
    }
    void Process(object o) {
        var context = o as HttpListenerContext;
        // process request and make response
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a VB.NET Windows Service that I wrote and it works fine. In
We have taken over some .NET 1.1 Windows Service code that spawns threads to
HI Guys, I have created a windows service which spawns three threads.The first thread
I have a .NET Windows serivce protected with {smartassembly} which works fine, except that
I wrote a VB.NET Windows Service, which works fine. I have only one issue
I have a .NET windows service which acts as a host for some wcf.
I have a .NET Windows service which self hosts a WCF service. This WCF
I have a dot net windows service project which contains multiple services. This has
I have a .NET Windows service and a .NET Web Application that I would
I have a multithreaded .NET Windows Service that hangs intermittently -- maybe once every

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.