So suppose I have ria services DomainDataService class:
public partial class SomeService : LinqToEntitiesDomainService<SomeEntities>
{
List<string> list = new List<string>();
public IQueryable<SomeEntity> GetSomeEntity()
{
list.Add("test");
...
}
}
There is a global variable list
. GetSomeEntity
method can obviously be called simultaneously. The question: is list
shared between parallel GetSomeEntity
invocation, i.e. do I have to protect it with locks?
I guess the same applies to all asp.net server side flavors, for instance web services (or not?).
It should depend on the context mode for the service. You can control this via an attribute:
[EnableClientAccess()]
[ServiceBehavior(ConcurrencyMode = ConcurrencyMode.Multiple)]
public partial class SomeService : LinqToEntitiesDomainService<SomeEntities>
{
I believe the default option is ConcurrencyMode.Single
.
From MSDN: "Setting ConcurrencyMode to Single instructs the system to restrict instances of the service to one thread of execution at a time, which frees you from dealing with threading issues"
So, to answer your question, the global list
is not shared between calls to your service (unless you make is static).