销毁wcf线程
我正在使用多线程 wcf maxConcurrentCalls = 10。通过记录对我的服务的调用,我看到 10 个不同的线程正在我的服务类中执行,并且它们在以下调用中被重用。
我可以告诉 WCF 销毁/删除一个线程,以便它在下一次调用时创建一个新线程吗?
这是因为我有线程静态状态,有时我想清除它(在意外异常时)。我正在使用线程静态范围来提高性能。
I'm using multithreaded wcf maxConcurrentCalls = 10. By logging calls to my service I see that 10 different threads are executing in my service class and that they are reused in the following calls.
Can I tell WCF to destroy/delete a thread so it will create a new one on the next call?
This is because I have thread-static state that I sometimes want to be cleared (on unexpected exceptions). I am using the thread-static scope to gain performance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
WCF 不创建新线程。它使用线程池中的线程来服务请求。因此,当请求开始时,它会从该池中提取一个线程来执行该请求,并在完成后将线程返回到池中。 WCF 在底层使用线程的方式是您不应依赖的实现细节。您永远不应该在 ASP.NET/WCF 中使用 Thread Static 来存储状态。
在 ASP.NET 中,您应该使用
HttpContext.Items
,在 WCF 中,您应该使用OperationContext
来存储整个请求中可用的某些状态。这是一篇不错的博客文章,您可以看一下,其中说明了抽象这一点的好方法。
WCF doesn't create new threads. It uses threads from a thread pool to service requests. So when a request begins it draws a thread from this pool to execute the request and after it finishes it returns the thread to the pool. The way that WCF uses threads underneath is an implementation detail that you should not rely on. You should never use Thread Static in ASP.NET/WCF to store state.
In ASP.NET you should use
HttpContext.Items
and in WCFOperationContext
to store some state that would be available through the entire request.Here's a good blog post you may take a look at which illustrates a nice way to abstract this.