Hosting on the UI Thread
Windows applications provide functionality by responding to messages. Each Windows application has a message queue and a window procedure that contains a message loop. The message loop retrieves messages from the message queue, one by one, and processes them, usually by forwarding the message to the appropriate target window. All controls on a form, for example, are also windows that have a unique window handle (HWND) and functionality to respond to particular windows messages.
Windows applications usually include some form of user interface that runs on a UI thread, meaning that messages are processed through the message loop. When WCF services are hosted inside a Windows application, operations can execute on thread pool threads or on the UI thread—as determined by design choices of both the service and its host. This brings to light some interesting considerations:
When services are hosted in a Windows application and hosted on the UI thread, the UI thread acts as a throttle for message processing—that is, messages are processed one at a time in the order received. To achieve additional throughput (process many requests concurrently) you may want to avoid hosting on the UI thread.
If you are concerned about hosting on the UI thread, you must also consider the location where you construct the
ServiceHost.ServiceOperationBehaviorsettings can be used to control whether services allow messages to be processed on the UI thread.When you are hosting a service ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access