且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

销毁WCF线程

更新时间:2022-06-12 20:58:12

WCF不会创建新线程.它使用线程池中的线程来服务请求.因此,当请求开始时,它将从该池中绘制线程以执行请求,并在完成后将线程返回到池中. WCF在下面使用线程的方式是您不应该依赖的实现细节.您永远不要在ASP.NET/WCF中使用静态线程"来存储状态.

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.

在ASP.NET中,您应该使用HttpContext.Items;在WCF OperationContext中,您应使用某些状态来存储整个请求.

In ASP.NET you should use HttpContext.Items and in WCF OperationContext 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.