WCF中的静态变量 [英] Static Variables in WCF

查看:98
本文介绍了WCF中的静态变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些WCF服务。这些服务在ASP.NET运行。我想这些服务能够访问一个静态变量。我的问题是,我不知道在哪里合适的服务器级别的存储机制。我不希望使用,因为速度的数据库。但是,我想静态变量保留在内存中尽可能长。其实,我想它留下来,直到我重新启动我的服务器,如果这一切成为可能。

I have some WCF services. These services run in ASP.NET. I want these services to be able to access a static variable. My problem is, I'm not sure where the appropriate server level storage mechanism is. I don't want to use the database because of speed. But, I want the static variables to stay in memory as long as possible. In fact, I'd like it to stay until I restart my server if it all possible.

谁能为我提供什么想法?

Can anyone provide me with any ideas?

推荐答案

您可以使用WCF静态变量,但你必须正确地同步访问他们,因为他们可能会被从多个线程同时访问。存储在静态变量的值都可以访问来自世界各地的AppDomain中,并保持在内存中,直到重新启动服务器。

You could use static variables in WCF but you must properly synchronize the access to them because they can potentially be accessed from multiple threads concurrently. The values stored in static variables are accessible from everywhere in the AppDomain and remain in memory until the server is restarted.

这篇关于WCF中的静态变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆