类和子类 [英] Classes and Subclasses

查看:60
本文介绍了类和子类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在将想法付诸实践时遇到困难.这个想法是我正在运行一个客户端服务器应用程序.客户端连接并发送数据(显然).在服务器端通过一个名为UserCollection的类来处理用户,该类在其中存储信息.我还希望每个客户端将所有正在运行的进程发送到服务器,以便我可以选择一个客户端并显示该用户的所有正在运行的进程.问题在于如何将客户端链接到ProcessCollections(即用于通过System.Diagnostics.Process.GetProcesses()存储所有进程的类).如何将类,数组中的进程链接到客户端.


谢谢,
Shmuli9

Im having problem putting an idea into practice. The idea is that i am running a client server application. The client connects and sends data (obviously). The users are dealt with at the server side by a class called UserCollection which stores there info. I also wanted each client to send all the running processes to the server so that i can select a client and show all the running processes from that user. The problem lies in how to link clients to ProcessCollections (thats the class used to store all the process via System.Diagnostics.Process.GetProcesses()). How do I link in the class, the processes in an array to the clients.


Thanks,
Shmuli9

推荐答案

不仅对于网络应用程序部分,而且对于两个不同的进程,代码和类都可以相同,但是对象,类实例是相同的总是不同的.进程之间是完全隔离的.为了进行通信,您需要IPC.在发送封装在类中的数据时,涉及到序列化.将实例(但通常是任意拓扑的整个对象图)序列化为字节数组,发送给另一个进程,然后在另一端进行反序列化. >
请参阅:
http://en.wikipedia.org/wiki/Serialization#.NET_Framework [ http://msdn.microsoft.com/en-us/库/vstudio/aa349369%28v=vs.90%29.aspx [ http ://msdn.microsoft.com/en-us/library/ms733127.aspx [ ^ ].

另请参阅我过去关于数据合同的答案:
如何在我的表单应用程序? [ ^ ],
创建属性文件... [反序列化json字符串数组 [ http://msdn.microsoft.com/en-us/library/kwdt6w2k%28v = vs.71%29.aspx [ ^ ],
http://msdn.microsoft.com/en-us/library/ms973857.aspx [ ^ ],
http://msdn.microsoft.com/en-us/库/vstudio/72x4h507%28v=vs.100%29.aspx [ http://msdn.microsoft.com/en-us/library/ms731190.aspx [ ^ ],
http://msdn.microsoft.com/en-us/library/ee354381.aspx [ ^ ],
http://msdn.microsoft.com/en-us/library/ms735103.aspx [ ^ ].

—SA
Not only for network application parts, but simply for a pair of different processes, the code and hence classes can be the same, but objects, class instances are always different. Processes are thoroughly isolated from each other. For communication, you need IPC. And when it comes to sending data encapsulated in classes, serialization is involved. An instance (but generally, a whole object graph of arbitrary topology) is serialized into an array of bytes, sent to another process and deserialized on the other end.

Please see:
http://en.wikipedia.org/wiki/Serialization#.NET_Framework[^],
http://msdn.microsoft.com/en-us/library/vstudio/aa349369%28v=vs.90%29.aspx[^].

One most advanced and easy-to-use method of serialization is Data Contract: http://msdn.microsoft.com/en-us/library/ms733127.aspx[^].

Please see also my past answers on Data Contract:
How can I utilize XML File streamwriter and reader in my form application?[^],
Creating property files...[^],
deseralize a json string array[^].

Serialization is already embedded in "classical" .NET remoting, and Data Contract — in WPF:
http://msdn.microsoft.com/en-us/library/kwdt6w2k%28v=vs.71%29.aspx[^],
http://msdn.microsoft.com/en-us/library/ms973857.aspx[^],
http://msdn.microsoft.com/en-us/library/vstudio/72x4h507%28v=vs.100%29.aspx[^],
http://msdn.microsoft.com/en-us/library/ms731190.aspx[^],
http://msdn.microsoft.com/en-us/library/ee354381.aspx[^],
http://msdn.microsoft.com/en-us/library/ms735103.aspx[^].

—SA


这篇关于类和子类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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