如何像访问类的实例一样访问进程? [英] How to access a process just like accessing an instance of a class?

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

问题描述

我有一个 DatabaseConnection dll,它执行以下操作... (1)connect(2)disconnect(3)ping/重建连接(4)做查询(5)等.它只是对 MySql.dll 的一种包装,专门用于满足我的需要.

现在, DatabaseConnection 将在另一个系统上被引用.
DatabaseConnection 少了Window.现在,我计划使用 DatabaseConnection 在同一命名空间中提供一个窗口工具,即使 DatabaseConnection 已经实例化,也可以随时调用/运行它.目的是为DatabaseConnection提供调试/记录工具(某种查询分析器).

我担心的是,如果 DatabaseConnection 已经作为另一个系统上的进程实例化/运行,那么如果 DatabaseConnection 已经存在,我将如何随时同步我的Window(QueryAnalyzer/Logging)工具?实例化/过程?

顺便说一下,我可以在不放置 DatabaseConnection 对象的情况下放置窗口.再次实例化窗口,而不会影响 DatabaseConnection 对象中的数据,反之亦然.窗户就像一个配件.

注意:我不打算将DatabaseConnection与窗口合并并隐藏它.

I have a DatabaseConnection dll which does the following...(1)connect (2)disconnect (3) ping/reestablish connection (4) do query (5) etc. It''s some sort of wrapper of the MySql.dll just customized to meet what I just need.

Now, the DatabaseConnection will be referenced on another system.
DatabaseConnection is Window less. Now, I have this plan to provide a window tool within the same namespace with the DatabaseConnection that can be called/run anytime even if DatabaseConnection is already instantiated. It''s purpose is to provide a debugging/logging tool (some sort of a query analyzer) for DatabaseConnection.

My concern is, if DatabaseConnection is already instantiated/run as a process on another system, how would I synchronize my Window (QueryAnalyzer/Logging) Tool anytime if the DatabaseConnection is already instantiated/a process?

By the way through this, I can dispose the window without disposing the DatabaseConnection object; Instantiate the window again without affecting the data in the DatabaseConnection object, and vice versa. The window is just like an accessory.

NOTE: I am excluding the idea to merge the DatabaseConnection with the window and just hide it.

推荐答案

如果您只想交换数据在您的过程之间,则可以使用管道.看一下该页面,看看它们如何工作:
http://msdn.microsoft.com/en-us/library/bb546102.aspx [ ^ ]

要使用管道,您需要服务器和客户端应用程序.我建议您将DatabaseConnection作为服务器,因为它将首先启动.

但是,管道将允许您发送和接收数据,而不是按要求共享对象.

据我所知,您不能在两个不同的进程之间共享对象的实例,因为它们不共享相同的地址空间(线程之间的共享是可以的,因为线程是在进程内执行的''空间). br/>
我建议使用管道从UI发送请求,然后这些请求将从您的DatabaseConnection中的另一个专用类解释,并将结果发送回UI.
If you just want to exchange data between your processes, then you may use pipes. Have a look to that page to see how they work:
http://msdn.microsoft.com/en-us/library/bb546102.aspx[^]

To use pipes, you need a server and a client application. I suggest that your DatabaseConnection be the server since it will be started first.

However pipes will allow you to send and receive data, not share objects as you asked.

As far as I know you can''t share an instance of an object between two different processes because they don''t share the same address space (sharing between threads is OK because threads are executing within the process'' space).

What I suggest is to use pipes to send requests from the UI, these requests will then be interpreted from another dedicated class in your DatabaseConnection and will send the result back to the UI.


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

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