WCF :: ServiceHost: Strange ... Still alive, even if the thread is dead?

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

After a little research, I decided to use WCF in my application to exchange data between processes, so I use the NetNamedPipeBinding.

The ServiceHost hosting application is not a dedicated server, so it must start ServiceHost through the stream. 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, despite the fact that the flow on which the server is running is excited, the client can still connect to serviceHost, and the service host processes the request correctly!

So, how does ServiceHost still process and process requests, although the main thread (the one that was created) is dead?

ServerThread , (true) {Thread. Sleep (100);?}

.

+3
1

Open ServiceHost, . , , , "Close" ServiceHost.

. ServiceHost . , , serviceHost.Close().

, :

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

+14

Source: https://habr.com/ru/post/1709481/


All Articles