我有以下配置的服務屬性WCF服務與ConcurrencyMode.Multiple和InstanceContextMode.Single行爲和多線程安全
[ServiceBehavior(ConcurrencyMode = ConcurrencyMode.Multiple, InstanceContextMode = InstanceContextMode.Single)]
public class UserService : IUserServiceContract
{}
我應該在這種情況下鎖定在服務中實現方法機制使用?
如果是,這是否正確實施?
[ServiceBehavior(ConcurrencyMode = ConcurrencyMode.Multiple, InstanceContextMode = InstanceContextMode.Single)]
public class UserService : IUserServiceContract
{
private readonly object LockObject = new object();
public Object1 GetObject1()
{
lock (LockObject)
{
using (var ob = new Object1)
{
return ob.Get();
}
}
}
public Object2 GetObject2()
{
lock (LockObject)
{
using (var ob = new Object2)
{
return ob.Get();
}
}
}
}
但在這種情況下,沒有共享資源... –
是的我同意,我的假設是這是虛擬代碼查看各種對象名稱。 – Tanner