两课之间的交流 [英] Communication between two classes

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

问题描述

我有一个网络类和一个对话框类,我必须将在网络类中接收到的数据发送到对话框类中,但不能直接发送,即它不应该与我的对话框紧密结合.帮帮我..............

I am having a network class and a dialog class.I have to send the data recieved in network class to dialog class but not direcly i.e it should not be tightly coupled with my dialog. Help me out..............

推荐答案

根据建议,您的网络类应在工作线程中运行,而GUI主要运行,请参见以下 Newcomer 文章:"WorkerThreads" [ ^ ](您可能会在他的书中找到许多有用的检测方法网页).

例如,您可以使用正确同步的共享资源来保存传入和传出的数据和消息(例如通过PostMessage),以使网络类通知数据到达.
As suggested, your network class should run in a working thread, while the GUI runs in the main one, see the following Newcomer''s article: "WorkerThreads"[^] (you may find a lot of useful assays in his webpage).

You may use, for instance, properly synchronized shared resources to hold incoming and outcoming data and messages (via, for instance, PostMessage) to make the network class notifying for data arrival.


这真是个坏主意.网络数据来来往往,但是对话框保持模态,直到用户关闭它为止.在网络流和模态行为之间存在明显的争议.您需要在单独的线程中运行所有网络应用程序级别的协议(在服务器端通常在两个线程中运行,一个接受新连接,另一个接受与客户端网络流的交换)–这是否合乎逻辑?

您对紧密耦合的担心是绝对正确的.

因此,您的网络事件可以通知UI,并且UI应该显示一些数据,状态等.正如我所说,模态行为几乎不适合网络设计.更好地在列表框或列表视图中显示数据.您可以实现在丢失的物品上行走,并在其他控件中显示数据的某些细节.

—SA
This is really bad idea. Network data is coming and coming but dialog stays modal until the user closes it. There is apparent controversy between network stream and modal behavior. You need to run all your network application-level protocol in a separate thread (on server side typically in two threads, one accepting new connections, another one performing exchange with clients'' network streams) — isn''t this logical?

Your concern about tight coupling is absolutely correct.

So, your network events can notify UI, and the UI should show some data, status, etc. As I say, modal behavior hardly fits the networking design. Better show data in something like list box or list view. You can implement walking by the lost items and displaying some detail of data in some other control.

—SA


这篇关于两课之间的交流的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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