A
A
Artem2014-08-29 20:28:23
.NET
Artem, 2014-08-29 20:28:23

In what cases does calling a method through a delegate not update the interface?

I am writing some software in VB .NET 2012 WinForms.
The main form has a LoadTree method, which, as the name implies, loads the tree (no matter where or how). To simplify, I'll cut the code:

Public Delegate Sub LoadTreeDelegate()
Sub LoadTree()
        tvMain.Nodes.Clear()
End Sub

When called from the form itself (by pressing a button or something else), the method executes and the tree is cleared.
There is a user control (also developed by me), from where I try to call the method of the main form through the delegate to reload the tree. I do it like this:
Dim d As New frmMain.LoadTreeDelegate(AddressOf frmMain.LoadTree)
d.Invoke()

Judging by the debugger, the method is being executed (the debugger enters it when the delegate is called) and the tree should be cleared. But this does not happen - the tree remains unchanged.
Can you suggest which way to dig?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Artem, 2014-08-29
@devspec

It was possible to do it through events, but the question remains open and interesting - why couldn't it be done through delegates?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question