静态对象在多个运行的应用程序中是同一个对象吗? [英] Is a static object the same object in multiple running applications?

查看:23
本文介绍了静态对象在多个运行的应用程序中是同一个对象吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果您有一个 windows 服务和一个 windows 窗体应用程序使用相同的静态对象,那么这两个应用程序中的对象是否相同?换句话说,如果我更新服务中的对象,如果两者同时运行,它也会在表单应用程序中更新吗?

If you have a windows service and a windows forms application that uses the same static object, is it the same object in both applications? In other words if I update the object in the service will it also be updated in the forms application as well if both are running at the same time?

推荐答案

它们运行在不同的进程上,因此它们不共享静态对象.

They run on different processes so they don't share the static object.

与您的问题不完全相关,但在同一应用程序上创建的线程是另一回事.他们将共享静态变量,除非用 ThreadStatic 属性

Not exaclty related with your question but threads created on the same application is a different story. They will share the static variable unless is marked with ThreadStatic attribute

这篇关于静态对象在多个运行的应用程序中是同一个对象吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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