views:

116

answers:

2

Why do i get System.Threading.ThreadStateException?

void setupTree(TreeView tv, MyObj o)
{

    tv.Invoke((MethodInvoker)delegate
    {
        tv.Nodes.Clear();
        tv.Nodes.Add("<root>").Tag = o;
        tv.SelectedNode = tv.Nodes[0]; //it happens here
    });
}
+1  A: 

Has the TreeView had its handle created yet?

Could you post a short but complete program to demonstrate this?

Jon Skeet
What do you mean? wouldn't it must have its handle created to make it to the 3rd tv line? I probably wont post up an example but i'll try clean it up enough to show a short example.
acidzombie24
i'm sure this helps noone but this may answer your handle question. http://i40.tinypic.com/eh0p3q.jpg
acidzombie24
Right, so it's already actually showing. Okay, that can't be it. When we've only got a single method to go by, we don't know whether it's been made visible or anything like that.
Jon Skeet
different error but it happens on the same line and my thinking was the same while writing this. It probably wont give you an idea but here you go. http://www.pastie.org/440598
acidzombie24
Downvoters: please explain, or your downvotes are useless.
Jon Skeet
A: 

I cannot replicate the problem... what version of the framework are you using?

jerryjvl
It has been resolved. I worked around the problem and it works fine without side effects.
acidzombie24