Compact C# .NET -> How to add TreeView's nodes/items from threads?

  • Thread starter Thread starter EOS
  • Start date Start date
E

EOS

Hi,

I am new to PDA development and my background is purely C/C++. Now I can get
the rought ideas on Compact C# .net for PDA development.

But I am having troubles on adding TreeView with nodes and items from
separate thread.

Hope someone can kindly share the lights with me. : )
 
Look at the TreeView.Invoke() method. It will allow you to run another method
within the UI thread.

This if off the top of my head but:

private void UpdateTree(string nodeName)
{
treeView1.Nodes.Add(nodeName);
}

private void SomeMethodInAnotherThread()
{
treeView1.Invoke(UpdateTree, new object[] { "my node name" });
}

I utilize this myself when using a seperate class that runs in another
thread an raises events by allowing the person to specify a parent control
(which should be your form) when creating the class instance, that way my
OnEvent methods can launch the event in the UI thread without the host form
worrying about multithreading:

public event InstallEnd;
public void OnInstallEnd( InstallEventArgs e )
{
if ( this.InstallEnd == null )
return;

if ( parent == null )
this.InstallEnd( this, e );
else
this.parent.Invoke( InstallEnd, new object[] { this, e } );
}


Chris
 
Thanks for the solution! : )

balmerch said:
Look at the TreeView.Invoke() method. It will allow you to run another
method
within the UI thread.

This if off the top of my head but:

private void UpdateTree(string nodeName)
{
treeView1.Nodes.Add(nodeName);
}

private void SomeMethodInAnotherThread()
{
treeView1.Invoke(UpdateTree, new object[] { "my node name" });
}

I utilize this myself when using a seperate class that runs in another
thread an raises events by allowing the person to specify a parent control
(which should be your form) when creating the class instance, that way my
OnEvent methods can launch the event in the UI thread without the host
form
worrying about multithreading:

public event InstallEnd;
public void OnInstallEnd( InstallEventArgs e )
{
if ( this.InstallEnd == null )
return;

if ( parent == null )
this.InstallEnd( this, e );
else
this.parent.Invoke( InstallEnd, new object[] { this, e } );
}


Chris


EOS said:
Hi,

I am new to PDA development and my background is purely C/C++. Now I can
get
the rought ideas on Compact C# .net for PDA development.

But I am having troubles on adding TreeView with nodes and items from
separate thread.

Hope someone can kindly share the lights with me. : )
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top