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 236133
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T20:19:14+00:00 2026-05-11T20:19:14+00:00

a new member here. Nice to see such a neat community. After a bit

  • 0

a new member here. Nice to see such a neat community.

After a bit of research, I decided to use WCF in my application to do inter process communication, so I am using the NetNamedPipeBinding binding.

The ServiceHost hosting application is not a dedicated server, so it has to spawn the ServiceHost via a thread. So far so good.

So I have something like the following:

Foo()
{
    Thread serverThread = new Thread(new ThreadStart(ServerThread));
    serverThread.Start();
    Console.WriteLine("Foo Exited");
}

ServerThread()
{
   Uri baseAddress = new Uri("net.pipe://localhost/service");
   ServiceHost serviceHost = new ServiceHost(typeof(MyService), baseAddress);
   ...
   serviceHost.Open();
   Console.WriteLine("Server Thread Exited");
}

So as expected, I see:

->   Server Thread Exited
->   Foo Exited

But to my surprise, even though the thread the server is running on has excited, the client can still connect to the serviceHost and the service host processes the request properly!

So how come the ServiceHost is still processing and treating requests even though it’s main thread (the one it was created on) is dead?

Also is there a better way to keep the ServerThread alive then a while(true){Thread. Sleep(100);}?

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-11T20:19:14+00:00Added an answer on May 11, 2026 at 8:19 pm

    When you call Open on the ServiceHost, an additional thread will be created to listen for incoming service requests. In this way, your thread may have finished running, but another thread has been created, and will continue to run until you call “Close” on the ServiceHost.

    It may not be necessary in your case to spawn off a thread yourself. Just Open your ServiceHost in the application’s main thread. You can then do other things in your main thread, and when you’re ready to kill the host, just call serviceHost.Close().

    Here’s a pretty good description I found:

    http://www.code-magazine.com/article.aspx?quickid=0701041&page=1

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

Sidebar

Related Questions

Hello is nice to be a new member of the community and thanks for
Dear community members, I am actually a bit new to CSS, however I know
a nice member here helped me out to create a form which adds steps
I'm a new member here and also new to python. My question is as
I am new to Android Application Development and a new member at stackoverflow. I
As I understand it I have to adorn a new member in a newer
I am new to stackoverflow as a member, although I follow this a lot
When accessing member that doesn't exist, automatically creates the object. $obj = new ClassName();
I'm new to Rails and making application where college members (teachers and students) can
If I don't use new to allocate the data members of a class, is

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.