I think you can create the hierarchy of TreeNodes on a worker thread, but
once the hierarchy is ready, the rest should happen on the UI thread.
In particular, make sure you assign the root node to the treeview on the UI
thread.
If you still get the exception, you will indeed have to create a parallel
hierarchical structure on the worker thread and to convert it to tree nodes
on the UI thread.
--
Sincerely,
Dmitriy Lapshin [C# / .NET MVP]
Bring the power of unit testing to the VS .NET IDE today!
http://www.x-unity.net/teststudio.aspx
"MrNobody" <(E-Mail Removed)> wrote in message
news:B2BBEF9E-FF5A-474F-B197-(E-Mail Removed)...
> Thanks for your reply! Well, I'm not exactly accessing a Treeview from a
> worker thread, what I'm doing is having a worker thread create a root
> TreeNode and then add children to it, then later when everything is done
> and
> I'm ready to display this to the UI , I create the dialog, the TreeView
> and
> just add this root node.
>
> Do I have to take the extreme step of creating a non-tree-specific
> structure
> in this worker thread, then once I'm ready for the UI to convert it into a
> tree?
>
> "Dmitriy Lapshin [C# / .NET MVP]" wrote:
>
>> Hi,
>>
>> The error message says it all - you are most likely accessing the
>> TreeView
>> control from a worker thread, which is prohibited.
>>