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.