Today I completed a webcast as part of a 15 part series - today's subject concurrency, throughput and throttling. I received some questions about callback and Windows client applications that I thought I would elaborate on here. In fact, I went a little overboard and created a bunch of samples that would illustrate the behavior of services and clients when you have a Windows client, a service with a callback contract (thus, two-way communication) and various WCF settings at the client and service that relate to concurrency, multithreading, synchronization with the UI thread, and so on.
The following table summarizes various settings at the client, service and callback and the resulting behavior at runtime. Here's the breakdown for each column:
I have also uploaded sample code for each of these scenarios, numbered in order of table row description below. Get the code here.
Callback Sync
Context
Callback Concurrency Mode
Service Operation
Callback Operation
Service Concurrency Mode
Resulting Behavior
True/
False
Single/
Reentrant/
Multiple
One-way/
Two-way
Single
These are defaults. InvalidOperationException at the service. Operation would deadlock calling the client application since the callback is two-way and reentrancy isn’t possible.
True
Service able to call client, but client is blocked because of outgoing call.
Service able to call client, client callback object is not blocked. If client callback object tries to communicate with UI thread (i.e., setting properties of controls) it will block.
One-way
Service able to call client, client callback object is not blocked. Client callback object can communicate with UI thread using Invoke() from callback thread. Client can issue multiple calls to service but only one callback can be processed at a time.
Service able to call client, client callback object is not blocked. Client callback object can communicate with UI thread using Invoke() from callback thread. Client can issue multiple calls and multiple callbacks can be processed at a time.
Two-way/
Multi-threaded Client
Service able to call client, client callback object is not blocked. Client callback object can communicate with UI thread using Invoke() from callback thread. Multiple calls from client can be processed at the service, and multiple callbacks can be processed at the client.
Service able to call client, client callback object is not blocked. Client callback can communicate with UI thread using Invoke() from callback thread. Multiple calls from client can be processed at the service, and multiple callbacks can be processed at the client.
Here is a summary of considerations.
Remember Me
Designed by NUKEATION STUDIOS