vb.net在课堂上调用 [英] vb.net Invoke in class

查看:87
本文介绍了vb.net在课堂上调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在调用时遇到问题,我有一个像这样的类,而在另一个里面

Hi, i have problem with invoke i have one class something like and inside another one

Public Class Form1
...........
...........
...........
public class client
 
...........
 Private Sub finish(ByVal message As String)
            If Me.InvokeRequired Then
                Me.Invoke(New send(AddressOf finish), message)
            Else
 
                Form1.report(message + " Left server")
                Form1.delete(message)
            End If
        End Sub
    End Class
 

end class
.....
end class


这给了我错误;调用;不是....
的成员 我不明白我怎么能在另一个类中使用invoke呢?

我得到了答案
那仅仅是因为您尚未实现一种称为Invoke的方法.我想这是故意的,因为您似乎认为类客户端继承了Control,该控件具有名为Invoke的方法.
因此,您将必须实现自己调用或从Control [^]继承.
同样,Form1.client.InvokeRequired


但是,当我在客户端类中放入继承控件"时,错误消失了,但是我似乎没有调用它.我想为文本框分配值,但是一旦添加继承控件",它就不会出现

希望您理解谢谢您.


and it gives me error ;Invoke; is not a member of ....
I don''t understand what''s wrong how I can use invoke in another class ??

I got answer
That''s simply because you have not implemented a method called Invoke. I guess that is intentional as you seem to think your class client inherits Control which has a method called Invoke.
So you''ll have to either implement Invoke yourself or inherit from Control[^].
The same goes for Form1.client.InvokeRequired


However when I put in client class "inherits control" error goes away but I doesn''t seem for me to invoke. I want to assign value to textbox but it doesnt come up once i add "inherits control"

I hope you understood thank you

推荐答案

您在类客户端中具有finish方法吗?将代码移动到Form1,因为这是可以确定InvokeRequired的控件.似乎您的类也不需要从Control继承,所以它不应该.

当线程想要更​​改UI时,您需要调用.您从线程调用的UI控件功能必须是线程安全的,并且需要检查是否需要InvokeRequired并在需要时调用Invoke本身.

在这里查看更多信息:
从线程更新UI-最简单的方法 [
You have the finish method in class client? Move the code to Form1 because that is the Control that can determine InvokeRequired. It also seems that your class would not need to inherit from Control so it shouldn''t.

You need to invoke when a thread wants to change the UI. The UI control function you call from the thread must be thread safe and would need to check if InvokeRequired and Invoke itself if needed.

Have a look here for more info:
Updating the UI from a thread - The simplest way[^]

I also see you call methods like this:
Form1.report(message + " Left server")



看起来Form1也是类名,这意味着您调用的是类方法,而不是对象的实例方法.也许您需要检查一下.

祝你好运!



It looks like Form1 is also the class name and this means that you call the class method and not the instance method of an object. Maybe you need to check that.

Good luck!


这篇关于vb.net在课堂上调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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