使用 ConcurrencyMode.Multiple 和 InstanceContextMode.PerCall 锁定 [英] Locking with ConcurrencyMode.Multiple and InstanceContextMode.PerCall

查看:27
本文介绍了使用 ConcurrencyMode.Multiple 和 InstanceContextMode.PerCall 锁定的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是否需要在使用 ConcurrencyMode.MultipleInstanceContextMode.PerCallInstanceContextMode.PerSession 的 WCF 服务中实现自己的锁定?由于在每次调用或新会话时都会创建一个新的 ServiceContext 对象,我应该认为我不会,但我不确定.

Do I need to implement my own locking in a WCF service that uses ConcurrencyMode.Multiple and InstanceContextMode.PerCall or InstanceContextMode.PerSession? Since a new ServiceContext object is created at every call or new session I should think that I would not, but I'm far from sure.

示例:

[ServiceBehavior(ConcurrencyMode = ConcurrencyMode.Multiple, InstanceContextMode = InstanceContextMode.PerSession,
     IncludeExceptionDetailInFaults = false, MaxItemsInObjectGraph = Int32.MaxValue)]
public class ExampleService : IExample

推荐答案

不,您不必添加锁定.每次调用都会获得一个新实例.

No you don't have to add locking. Each call will get a fresh instance.

但是,如果您需要来自特定调用者的状态,则必须手动处理.

However, if you need state from a particular caller, that will have to be handled manually.

请参阅此线程 了解更多信息

See this thread for more information

这篇关于使用 ConcurrencyMode.Multiple 和 InstanceContextMode.PerCall 锁定的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆