Click here to Skip to main content
15,747,908 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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:

VB.NET
'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


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

Edit: updated code
Posted
Updated 10-Feb-12 8:19am
v3
Comments
Sergey Alexandrovich Kryukov 1-Feb-12 1:28am    
"Not working" is not informative.
Is there a compilation error, exception? Where? How about complete information? If not, what happens?
--SA
Herman<T>.Instance 1-Feb-12 15:38pm    
all you do is invoke a NEW object. So everything in it can be NULL
The_Chaoz 8-Feb-12 15:25pm    
sorry i was on hollidays. The objects on the invoke are not null cause it's a control and it does exist. The delegate functions just doesn't get called, so "Lines" it's null.

1 solution

"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.
 
Share this answer
 
Comments
The_Chaoz 9-Feb-12 14:39pm    
The timer call several objects to analize them (it's a parser), and to avoid cross threads calls I use delegates. but one of them just doesn't work.
Christian Graus 9-Feb-12 14:39pm    
I've been asking for days, is there a line of code that sets this delegate ?
The_Chaoz 9-Feb-12 16:04pm    
All the code that is related to this delegate is there.
Christian Graus 9-Feb-12 16:23pm    
Oh, I don't do VB, so, I missed that compact syntax. Nice. You're in a thread ? One thing you can do is use a BackgroundWorker and use the progress changed mechanism to call the main thread to do stuff.
The_Chaoz 9-Feb-12 23:19pm    
I'll have to use delegates as well and probably I'll get the same problem.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900