can use static methods/ classes safely in WCF due to the fact that WCF creates a new thread for each user, so if i’ll have a static variable
public static int = 5
and if two clients will try to change it simultaneously, will one of them will be able to change it for the other?
thanks…
Well anyone can modify static field and they will see the latest value set depending upon thread and processor scheduling. However for safe implementation you should define one more static object and use it for lock and provide your access to variable through static property.
This is thread safe as well as is shared for every threads and every instance as long as Service Host of WCF keeps process alive.
In IIS or any such process model, if process is recycled, you will loose the last static value.
You should use some sort of server/application level store. e.g. HttpContext.Current.Server (in case of ASP.NET).