Control.Invoke Questions

thuli
03-30-2004, 12:12 PM
Hi, I am new to this forum (all forums, actually). I have read several and found them helpful, but I couldn't find anything to help me with this problem. I am trying to create a thread and from within the thread, add a node to a treeview. But I get the following error:
-
The action being performed on this control is being called from the wrong thread. You must marshal to the correct thread using Control.Invoke or Control.BeginInvoke to perform this action.
-
My code is:
-
Private Sub frmMain_Load(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles MyBase.Load

Dim t As New Threading.Thread(AddressOf Go)
t.Start()
t = Nothing
End Sub

Private Sub Go()
TreeView1.Nodes.Add("NodeInfo")
End Sub
-
I'm thinking I have to use delegates, but I cannot, for the life of me, figure it out. Any help would be appreciated. Thanks.

Jason Thuli
thuli@chartermi.net

Machaira
03-31-2004, 07:32 AM
Why are you using a thread to fill the treeview?

thuli
03-31-2004, 07:46 AM
Why are you using a thread to fill the treeview?

Basically, I am trying to make a program similar to Windows Media Player 9. I am using a new thread to check different folders for any activity, and it may be checking several folders, and I do not want it to slow down the rest of my program. Like I said, I am new and trying to learn the tricks to making a good application. I assumed threading is a pretty important part of that. If there is a better way to do this, please let me know. Thanks.

Jason Thuli
thuli@chartermi.net

ps. The small example of my problem that I sent in my first message was really nothing. It was my problem simplified to the bare minimum, to save space in the forum.

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum