title: How to populate treeview in backgroundworker C#
body: <p>I have those below code that populate a treeview named treeView1 with data from JSON file using JSONnet. If I open a large json file, the UI hang during the populating progress, so how can I make everything happen in a backgroundworker and show a progressbar for populating progress? thanks</p>
  
  <pre><code>    private void button1_Click(object sender, EventArgs e)
      {
          OpenFileDialog openFileDialog1 = new OpenFileDialog();
          openFileDialog1.InitialDirectory = "c:\\";
          openFileDialog1.Filter = "All files (*.*)|*.*";
          openFileDialog1.FilterIndex = 1;
          openFileDialog1.RestoreDirectory = true;
          if (openFileDialog1.ShowDialog() == DialogResult.OK)
          {
              string jsonfile = File.ReadAllText(openFileDialog1.FileName);                
              try
              {
                  var jsondata = JObject.Parse(jsonfile);
                  treeView1.Nodes.Clear();
                  AddObjectNodes(jsondata, "DATA", treeView1.Nodes);
              }
              catch (Exception)
              {
                  MessageBox.Show("Invalid JSON");                    
              }
          }
      }
      private void AddObjectNodes(JObject @object, string name, TreeNodeCollection parent)
      {
          var node = new TreeNode(name);
          parent.Add(node);
  
          foreach (var property in @object.Properties())
          {
              AddTokenNodes(property.Value, property.Name, node.Nodes);
          }
      }
  
      private void AddArrayNodes(JArray array, string name, TreeNodeCollection parent)
      {
          var node = new TreeNode(name);
          parent.Add(node);
  
          for (var i = 0; i &lt; array.Count; i++)
          {
              AddTokenNodes(array[i], string.Format("[{0}]", i), node.Nodes);
          }
      }
  
      private void AddTokenNodes(JToken token, string name, TreeNodeCollection parent)
      {
          if (token is JValue)
          {
              parent.Add(new TreeNode(string.Format("{0}: {1}", name, ((JValue)token).Value)));
          }
          else if (token is JArray)
          {
              AddArrayNodes((JArray)token, name, parent);
          }
          else if (token is JObject)
          {
              AddObjectNodes((JObject)token, name, parent);
          }
      }
  </code></pre>