Callbacks and Synchronization Context
Similar to a service invocation, the callback may need to access resources that rely on some kind of thread(s) affinity. In addition, the callback instance itself may require thread affinity for its own use of the TLS or for interacting with a UI thread. While the callback can use techniques such as those in Examples 8-4 and 8-5 to marshal the interaction to the resource synchronization context, you can also have WCF associate the callback with a particular synchronization context by setting the UseSynchronizationContext
property to true
. However, unlike the service, the client does not use any host to expose the endpoint. If the UseSynchronizationContext
property is true
, the synchronization context to use is locked in when the proxy is opened, or, more commonly, when the client makes the first call to the service using the proxy, if Open( )
is not explicitly called. If the calling client thread has a synchronization context, this will be the synchronization context used by WCF for all callbacks to the client’s endpoint associated with that proxy. Note that only the first call (or the call to Open( )
) made on the proxy is given the opportunity to determine the synchronization context. Subsequent calls have no say in the matter. If the calling client thread has no synchronization context, even if UseSynchronizationContext
is true
, no synchronization context will be used for the callbacks.
Callbacks and UI Synchronization Context
If the callback ...
Get Programming WCF Services now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.