代表有问题 [英] Problem with delegates

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

问题描述

好吧,我会解释一下,以便您理解.

我正在创建一个IDE,为此,我为每个实例编码了一个类(我为此实例使用一个列表,"List(Custom_Class)"),在每个实例上都有一个包含所有功能的列表可以在此实例上使用.
现在,我用一个计时器填充此列表,因此我使用委托来避免使用"CheckForIllegalCrossThreadCalls".现在我有一个问题,我在计时器上使用的此委托不起作用.这是代码:

Well i''ll explain a bit for you to understand.

I''m creating a IDE, for this i''ve coded a class for each instance (i use an list for this instances, "List(of Custom_Class)"), on each instance there''s a list with all the functions that can be used on this instance.
Now i fill this list trow a timer, so i use delegates to avoid the use of "CheckForIllegalCrossThreadCalls". Now i got a problem, this delegate that i use on the timer is not working. here is the code:

'delegate declaration
Delegate Function SelectedLine(ByVal tControl As Scintilla) As ScintillaNet.LinesCollection

'Timer.Tick event
Dim LinesDelegate As New SelectedLine(AddressOf GetLineCollection)

With Instances(If(TabControl1.InvokeRequired, SelectedTabIndexDel.Invoke(TabControl1), TabControl1.SelectedIndex))'this work perfect
If .SyntaxHandle.InvokeRequired Then
    If .SyntaxHandle.InvokeRequired Then
        Lines = LinesDelegate.Invoke(SyntaxHandle)'It's the same as calling the method with out the delegate (cross thread call)
    Else
        Lines = .SyntaxHandle.Lines
    End If
    For Each line As ScintillaNet.Line In Lines'Lines is like a null object when the invoke is required
        'if .invoke is used, then each "line" is a null object, other way it's not.
        'code
    Next
End With

'Delegate Function
Private Function GetLineCollection(ByVal tControl As Scintilla) As ScintillaNet.LinesCollection
    Return tControl.Lines'It's the same as calling the method with out the delegate (cross thread call)
End Function



注意:实例"是包含所有实例的列表. SyntaxHandle是来自实例(我的自定义类)的控件,用于保存文本.


如果我忽略了一些重要的知识,请告诉我,以便我可以添加.

在此先感谢

更新了代码



Note: Instances is the List what contains all instances. SyntaxHandle is a control from Instance (my custom class) that hold the text.


If i omit something important to understand please let me know so i can add it.

Thanks in advance

updated code

推荐答案

,因此我使用委托来避免使用" CheckForIllegalCrossThreadCalls."

我不认为如果使用计时器,则不应获得此异常.我不清楚您为什么需要使用委托,并且经过数天的阅读,目前尚不清楚您的问题是什么.而且我看不出您的代表在什么地方挂了电话.
"so i use delegates to avoid the use of "CheckForIllegalCrossThreadCalls". "

I don''t believe that you should get this exception if you''re using a timer. I''m unclear why you need to use delegates, and having read this over several days, I am unclear what your problem is. And I don''t see where your delegate is hooked up to do anything.


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

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