So I want to make sure all of my database / network operations are not happening on the UI thread of my application. To do this I normally use the BeginInvoke function to make the call and then Invoke to do the actual update. I am not sure if I am doing things correctly compared to the way it should be done. Could anyone please provide comments on the following code:
private void folderTree_NodeExpandedChanged(object sender, RadTreeViewEventArgs e)
{
if (e.Node.Tag != null)
{
var path = (string) e.Node.Tag;
if (!string.IsNullOrEmpty(path))
{
if (Directory.Exists(path))
{
folderTree.BeginUpdate();
BeginInvoke(
new Action(() => GetDirectories(path, e.Node)));
folderTree.EndUpdate();
}
}
}
}
private void GetDirectories(string path, RadTreeNode parent)
{
var dirs = (new DirectoryInfo(path)).GetDirectories();
Array.ForEach(dirs, d => Invoke(new Action(
() => AddNode(d.Name, d.FullName, parent))));
}