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

  • Home
  • SEARCH
  • 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 3967326
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T03:42:23+00:00 2026-05-20T03:42:23+00:00

I am using the class HttpListener as a web server. This server runs on

  • 0

I am using the class HttpListener as a web server. This server runs on a different thread.
At some point this server needs to run some code but it needs to be executed on the main thread. Is there an easy way of doing that?

Thanks!

  • 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-20T03:42:24+00:00Added an answer on May 20, 2026 at 3:42 am

    The bigger question is:

    Why do you need to run it on the parent thread? Is it UI Code modifying the UI? Do you need to be within that thread’s context to gaurantee thread saftey?

    It might be worth stepping back and re-evaluating your threading model, you may be trying to do things in the wrong place.

    I Suggest you read This Excelent Free E-Book on C# Threading and learn about the alternate ways of inter-thread communication and look into the Dispatcher if you’re using WPF, as it will help delegate events back to the UI Thread if that’s what your intent is.

    Quick & Dirty Solution Not really the best way

    There’s any number of ways to approach this, the simplest would probably to have a list of delegates to execute on the main thread. Each time your main thread spins, you lock the collection (unless you’re using the multi-threaded collections) and copy out the delegates & clear the collection and release the lock.

    Then you simply run them on the main thread.

    The problem you’ll run into is if you’re using blocking on the main thread, your spin cycle will not pass across your delegates till your blocking stops. So if you’re say, blocking while you wait for connections, your code will not run till a new person connects.

    You could put the server’s listen port on it’s own thread to solve this.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using HttpListener Class to produce a local web server. But by default,
Im using class.twitter.php ( http://emmense.com/php-twitter/documentation/v11-methods-available/ ) Im using this code: $summize = new summize;
I tried creating a simple HTTP server using System.Net.HTTPListener, but it doesn't receive connections
I'm using class from some assembly(source code is not available), so it is not
Language: PHP / Using Class Upload by Colin Verot About: Multiple Uploading The code
i load a class using Class.forName(klassname,false,loader) After this i create an instance using klass.newInstance();
I would like to expand the functionality of some class using class_eval. I would
I know basics of UML and java's OO interpretations using class diagrams. But after
I am using TimeStamp class to convert seconds into Day,Hours,Minutes,Seconds. I used following code
I wrote a simple WebServer using HttpListener class (.net 2.0) It seems that It

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.