Results 1 to 4 of 4

Thread: TreeView problem

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Feb 2001
    Location
    Houston, TX
    Posts
    342

    TreeView problem

    Every time I try to add a node to a tree view I get the following message:

    Code:
    Additional information: The action being performed on this control is being called from the wrong thread. You must marshal to the correct thread using Control.Invoke or Control.BeginInvoke to perform this action.
    I have not threaded this project, my add method is being called from a private sub.

    Any ideas??

    Thanks!

  2. #2
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649
    Where is the code located?
    A .Net control is private to the Form that it is placed so you can't add nodes in a Sub that doesn't belong to the Form.

  3. #3
    Lively Member
    Join Date
    Aug 1999
    Location
    Amsterdam
    Posts
    117
    This error message you get tipically when you call a method on a control from other than the UI thread. You said you don't write multi threaded code in that app, but there are scenarios when the runtime creates new threads implicitly for you, with Async Delegates for example. So first try to find out if that's the case, by getting the HashCode of the CurrentThread (C#: MessageBox.Show(Thread.CurrentThread.GetHashCode().ToString()); )

    If this is the case you should use Invoke or BeginInvoke.
    (BeginInvoke = Async and Invoke = Sync)

  4. #4

    Thread Starter
    Hyperactive Member
    Join Date
    Feb 2001
    Location
    Houston, TX
    Posts
    342
    The code is in an event of another control, all on the same form. It did tell me I need to use the begin invoke method (Visual Basic) however, there are no examples on how do do that.

    Thanks for the help!!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width