Section C.9. Concurrency Management


C.9. Concurrency Management

  1. Always provide thread-safe access to:

    1. Service in-memory state with sessionful or singleton services

    2. Client in-memory state during callbacks

    3. Shared resources

    4. Static variables

  2. Prefer ConcurrencyMode.Single (the default). It enables transactional access and it is thread-safe without any effort.

  3. Keep operations on single-mode sessionful and singleton services short in order to avoid blocking other clients for long.

  4. When using ConcurrencyMode.Multiple, you must use transaction auto-completion.

  5. Consider using ConcurrencyMode.Multiple on per-call services to allow concurrent calls.

  6. Transactional singleton service with ConcurrencyMode.Multiple must have ReleaseServiceInstanceOnTransactionComplete set to false:

     [ServiceBehavior(InstanceContextMode = InstanceContextMode.Single,                  ConcurrencyMode = ConcurrencyMode.Multiple,                  ReleaseServiceInstanceOnTransactionComplete = false)] class MySingleton : IMyContract {...} 

  7. Never self-host on a UI thread and call the service by the UI application.

  8. Never allow callbacks to the UI application that called the service unless the callback posts the call using SynchronizationContext.Post( ).

  9. Use the asynchronous calls pattern on the client side only.

  10. When supplying the proxy with both synchronous and asynchronous methods, apply the FaultContractAttribute only to synchronous methods.

  11. Do not mix transactions with asynchronous calls.




Programming WCF Services
Programming WCF Services
ISBN: 0596526997
EAN: 2147483647
Year: 2004
Pages: 148
Authors: Juval Lowy

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net