开发者

Does WCF execute the operations in a Singleton WCF service in the same thread?

I've service which is marked with the ServiceBehavior attribute

[ServiceBehavior(InstanceContextMode=InstanceContextMode.Single,
 ConcurrencyMode = ConcurrencyMo开发者_开发知识库de.Multiple)]

Is there any chance for the operations in this service to be executed by same thread?

I'm storing an important data in ThreadLocal variable, which is to be used for single execution of an operation.


No,

Each request is answered in a different thread. the InstanceContextMode.Single attribute specifies that the service uses the same object (and its members) for each request.


Be aware that threads in WCF are handled by ThreadPool => Thread is not disposed after request processing but returned to pool so it can be reused for other request processing. I'm not sure how this works with ThreadLocal<T> but with ThreadStaticAttribute this can easily pass the value from one request processing to next random request processing which will use the same Thread.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜