什么是一个静态类的范围有多大? [英] What is the scope of a Static Class?

查看:241
本文介绍了什么是一个静态类的范围有多大?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有可能由一个以上的过程在一个时间使用的组件。如果我使用一个静态类,将在多个进程都使用这个类的同一实例?

I have an assembly that may be used by more than one process at a time. If I am using a static class, would the multiple processes all use the same "instance" of that class?

由于过程是分离的,将这些差异下的应用程序域运行,因此具有静态实例分开?

Since the processes are separate, would these be running under difference Application Domains, hence have the static "instances" separate?

在这里的细节的布丁是该组件正在使用,我的设置来并行处理的批次中的消息的自定义的BizTalk适配器。这就是我呼吁上述多进程。

The pudding in the details here is that the assembly is being used by a custom BizTalk adapter that my be set to process the messages in parallel batches. That is what I am calling "multiple processes" above.

感谢您,

基思

Thank you,
Keith

推荐答案

多个线程将分享一个实例。出于这个原因,静态类可以方便的在线程之间传递状态,但你必须非常小心,不要引入竞争条件(显示器您的属性)。

Multiple threads would share an instance. For this reason a static class can be convenient for passing state between threads, but you need to be very careful not to introduce race conditions (Monitor or lock your properties).

然而,多的过程的应该是在单独的应用程序域,因此每个人都有自己的实例。

However, multiple processes should be in separate AppDomains and therefore each have their own instance.

这篇关于什么是一个静态类的范围有多大?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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