跨多个进程访问类对象的实例 [英] Accessing instancess of a class object across multiple processes

查看:263
本文介绍了跨多个进程访问类对象的实例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,

我对C#比较新。我在一个名为PROJ001.exe的项目中创建了一个MYCLASS类的全局实例,并且可以在此项目中成功访问来自各种表单的同一实例。我现在必须从PROJ001.exe调用其他进程(例如PROJ002.exe,PROJ003.exe PROJ004.exe等...)。如何从PROJ002.exe访问PROJ001.exe中创建的MYCLASS对象的相同实例?



问候

Pat

Hello,
I''m relatively new to C#. I have created a global instance of a class MYCLASS in a project called PROJ001.exe and can successfully access the same instance from various forms within this project. I now have to call other processes from PROJ001.exe (eg PROJ002.exe, PROJ003.exe PROJ004.exe etc...). How can I access the same instance of the MYCLASS object that was created in PROJ001.exe from PROJ002.exe ?

regards
Pat

推荐答案

进程间通信是一个非常复杂的主题,并不适合初学者。因为你是一个初学者,当你为了好玩而编码时,你显然是在制造东西,忘记这一点,这真的不是一个很好的途径,现实世界中的人几乎从不这样做。



如果在现实世界中编程的人需要这样做,匿名管道是一个很好的方法。 http://msdn.microsoft.com/en-us/library/bb546102.aspx [ ^ ]
Inter process communication is a really complex topic, not really suited to beginners. As you''re a beginner, you''re clearly making stuff up as you code for fun, forget about this, it''s really not a great avenue to go down, people in the real world almost never do this any how.

If anyone who is programming in the real world needs to do this, anonymous pipes are a good way to go. http://msdn.microsoft.com/en-us/library/bb546102.aspx[^]

使用远程处理和进程间通信。您也可以使用WCF,甚至可以使用套接字自行编辑。如果其中一个可执行文件加载/运行其他可执行文件,那么您也可以加载应用程序域,有很多方法可以做到这一点,最好的方法实际上取决于您想要做什么,而不是如何做。 IPC可能就像把大锤拿在钉子上一样,但没有更多关于你想要完成什么的信息很难说明在你的情况下使用什么。
Using Remoting and Inter-Process Communication. You can also use WCF or even go as far as rolling your own with sockets. If one of the executables loads/runs the others, then you can also load in app domains, there are a multitude of ways to do this, the best way really depends on what you are wanting to do, rather than how. IPC may be like taking a sledge hammer to a picture nail, but without more information about what you are wanting to accomplish its hard to say what to use in your situation.


这篇关于跨多个进程访问类对象的实例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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