Call method on a form from another thread

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • C.C. \(aka Me\)

    Call method on a form from another thread

    I am looking for a sample of how you execute/invoke a method in a form from
    one thread and have it run on the thread that created the form instead of
    the thread that actually made the call. The reason I need this is because
    the method that gets invoked could be updating any number of GUI elements on
    the form.

    What would be ideal is to have the code in the thread an not the form since
    I will have several of these forms.

    Also, do delegates perform this action themselves? What I mean is if I
    delegate is declared as part of one thread but a handler is registered by
    another thread does it make sure it executes on the correct thread?

    Thanks.
    --
    ~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~
    Charles Cox
    VC/VB/C# Developer
    ~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~


  • Mark R. Dawson

    #2
    RE: Call method on a form from another thread

    John Skeet has a very good article on threading in .Net, one section is
    dedicated to threading issues in Windows Forms, it should answer your
    questions:



    Mark Dawson




    "C.C. (aka Me)" wrote:
    [color=blue]
    > I am looking for a sample of how you execute/invoke a method in a form from
    > one thread and have it run on the thread that created the form instead of
    > the thread that actually made the call. The reason I need this is because
    > the method that gets invoked could be updating any number of GUI elements on
    > the form.
    >
    > What would be ideal is to have the code in the thread an not the form since
    > I will have several of these forms.
    >
    > Also, do delegates perform this action themselves? What I mean is if I
    > delegate is declared as part of one thread but a handler is registered by
    > another thread does it make sure it executes on the correct thread?
    >
    > Thanks.
    > --
    > ~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~
    > Charles Cox
    > VC/VB/C# Developer
    > ~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~
    >
    >
    >[/color]

    Comment

    Working...