Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multi-threaded self-hosting WCF service

Tags:

.net

wcf

It looks like WCF only uses one thread when using self hosting. I'd like to use several threads or a thread pool of some kind for this. Is it possible with self hosting configuration or I need to use IIS for this?

like image 890
Max Avatar asked Apr 20 '11 17:04

Max


1 Answers

If you self host the service in UI application with default service behavior setting you will probably see the behavior you are describing. Default service behavior uses synchronization context. In case of starting the service host in the UI thread (WinForms, WPF) all requests are routed to the common windows message loop => all requests are handled sequentially by UI thread.

In any other case (including manually setting [ServiceBehavior(UseSynchronizationContext = false)] for services hosted in the UI thread) the service host dispatches new thread from the thread pool for each request. There are some further differences based on instance context mode and concurrency mode but with default settings you will see the behavior I described.

like image 105
Ladislav Mrnka Avatar answered Nov 02 '22 23:11

Ladislav Mrnka