Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Loading Treeview in the Background

Loading Treeview in the Background

Scheduled Pinned Locked Moved C#
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    smarttom99
    wrote on last edited by
    #1

    I have a large treeview I need to build and it takes about 1 minute to load. what I'd like to do is load the treeview in background. I tried doing it through, but it causes the main form to freeze until it's complete. Does anyone know what the best process is to load things in the background not affecting the main application screen. Thanks.

    H 1 Reply Last reply
    0
    • S smarttom99

      I have a large treeview I need to build and it takes about 1 minute to load. what I'd like to do is load the treeview in background. I tried doing it through, but it causes the main form to freeze until it's complete. Does anyone know what the best process is to load things in the background not affecting the main application screen. Thanks.

      H Offline
      H Offline
      hdv212
      wrote on last edited by
      #2

      Hi Use System.Threading to Perform your request (Loading Treeview) Good Luck

      L 1 Reply Last reply
      0
      • H hdv212

        Hi Use System.Threading to Perform your request (Loading Treeview) Good Luck

        L Offline
        L Offline
        louthy
        wrote on last edited by
        #3

        Or even easier (if you're using .NET 2.0) is to drop a BackgroundWorker process onto the form. It's DoWork event will fire a method on the form where you can do your processing. Be warned however, that Windows Forms aren't thread safe, so any manipulation of the form controls requires jumping back onto the main thread using Control.Invoke or Control.BeginInvoke to call a delegate. Eg. public partial class MyForm { // Your delegate definition. It basically defines the prototype of the method. delegate void AddItemDelegate(string text); // Method for adding a single item to your list private void AddItem(string text) { if (InvokeRequired) { // We're not in the UI thread, so we need to call BeginInvoke BeginInvoke(new AddItemDelegate(AddItem), new object[] { text }); return; } myListBox.Items.Add(text); } // Your DoWork event private void myListBox_DoWork(object sender, DoWorkEventArgs e) { foreach( string item in myList ) { AddItem(item); } } }

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups