对象之间的通讯 [英] communication between objects

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

问题描述

conn.Open()
 f1.msg();
 conn.Close();



有2种情况1是form1和2nd,我现在建立连接,我在类中建立连接,然后使用conn.open和open打开连接,我在函数form1类中调用了函数f1,现在在thr上我显示msg框,现在我想去我的连接类,并在特定的行conn.close我该怎么做



there is 2 clases 1 is form1 and 2nd i make called connection now i make connection in my class and i open connection by using conn.open and thn i called function f1 which in form1 class now at thr i show msg box now i want to go bak to my connection class and in that particular line conn.close how i do this

推荐答案

我不确定你为什么认为那是个好主意.
我能想到的唯一原因是,如果form1中的方法将显示来自连接的信息-这意味着这里存在一些潜在的问题:
如果您的连接使用的不是与form1实例相同的线程,则除非您使用Invoke,否则任何显示信息的尝试都将失败. 如果您的方法依赖实际通过连接进行通信,那么它可能不会立即完成其处理-如果它使用任何阻塞调用,那么它将冻结正在从中调用它的线程-因此,如果该方法来自另一个表单用户界面(例如,单击按钮或类似按钮),它将锁定该表单,直到返回为止.
如果不使用阻塞,则它将返回-并且您将关闭连接-在处理完成之前.

您想实现什么,您认为这是一个很好的解决方案?可能会有更好,更轻松的方法.
I''m not sure why you think that would be a good idea.
The only reason I can think of that you would want to do this, is if the method in form1 is going to display information from the connection - which means there are a couple of potential problems here:
If your connection is not using the same thread as the form1 instance, then any attempt to display information is going to fail, unless you use Invoke.
If your method relies on actually communicating via the connection, then it may not complete it''s processing immediately - if it uses any blocking calls, then it will freeze the thread from which you are calling it - so if that comes from a different forms UI (a button click or similar, say) then it will lock that form up until it returns.
If it doesn''t use blocking, then it will return - and you will close the connection - before processing if complete.

What are you trying to achieve, that you think this is a good solution? There may be a better, easier, way to do it.


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

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