English 中文(简体)
在多个运行申请中,静态物体是否相同?
原标题:Is a static object the same object in multiple running applications?

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.

并非与你的问题有关,而是在同一个应用上制造的透镜是一个不同的故事。 除非标有http://msdn.microsoft.com/en-us/library/system.threadstaticattribute.aspx” rel=“noreferer”>ThreadStatic

问题回答

否,除非你为实现这一目标而做一些具体的工作,否则不会在不同的进程之间分享。

这方面的简单答案是,每个进程都有自己的静态,因此不会在服务和桌面程序之间分享。

复杂部分是,在<<>single进程中甚至可能出现多个静态情况。

http://www.ohchr.org。 每一次<代码>ClassLoader的静态物体都有一例。 我在<代码>C#上对等功能进行了核对。 I found . Thiss question on SO, 表明在中确实存在类似于多个舱载重机的情况。 C# (I guess actual in CLR),尽管我没有发现任何具体提到静态的多个事例,但我确信情况是这样。

Simply put no,
static is static per AppDomain (and you could have multiple domains per process), so not even for one process is safe to assume that your static variables will be shared (normally is true unless you create new domains by hand, e.g. see What is AppDomain?) - e.g. web apps typically break the static singletons etc.
In other words you need to use some sort of persistence to be able to share your data in between different applications. Or use remoting, WCF to communicate over application (domain) boundaries.

我认为,每一项申请都是在自己的过程中进行的。 我确实怀疑,更新视窗服务的固定物体对作为视窗申请的固定物体具有任何影响。

视窗服务在<代码> 系统账户下,作为视窗申请表在<代码>User账户下运行。

As others have pointed out in the comments, the processes run in different memory. Each process has its own address space.

视窗服务响应服务管理人员的指挥。

它们完全是两条不同的东西。





相关问题
Bring window to foreground after Mutex fails

I was wondering if someone can tell me what would be the best way to bring my application to the foreground if a mutex was not able to be created for a new instance. E.g.: Application X is running ...

How to start WinForm app minimized to tray?

I ve successfully created an app that minimizes to the tray using a NotifyIcon. When the form is manually closed it is successfully hidden from the desktop, taskbar, and alt-tab. The problem occurs ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

Handle DataTable.DataRow cell change event

I have a DataTable that has several DataColumns and DataRow. Now i would like to handle an event when cell of this DataRow is changed. How to do this in c#?

Apparent Memory Leak in DataGridView

How do you force a DataGridView to release its reference to a bound DataSet? We have a rather large dataset being displayed in a DataGridView and noticed that resources were not being freed after the ...

ALT Key Shortcuts Hidden

I am using VS2008 and creating forms. By default, the underscore of the character in a textbox when using an ampersand is not shown when I run the application. ex. "&Goto Here" is not ...

WPF-XAML window in Winforms Application

I have a Winforms application coded in VS C# 2008 and want to insert a WPF window into the window pane of Winforms application. Could you explain me how this is done.