Create forms from threads

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Kevin Chabot

    Create forms from threads

    Hi,

    I need to be able to create one or more form(s) from a method that is
    called from different threads. When this form is created, it appears but
    it does not receive any message. It looks blank, and when you move your
    cursor over it, it becomes an hourglass.

    Can anyone help me with this?
    Thanx in advance...

    Kind regards,
    Kevin Chabot
  • Nicholas Paldino [.NET/C# MVP]

    #2
    Re: Create forms from threads

    Kevin,

    What you will want to do is call the Invoke method on a control that is
    hosted on the main UI thread. This method will take a delegate and an array
    of objects (the parameters) and call the target of that delegate in the main
    UI thread. You would create a delegate which would point to a method which
    creates and shows the form.

    You could also run a new message loop through a call to the static Run
    method on the Application class in the new thread, but I would advise
    against that (it's not common practice, and I don't think the Run method was
    meant to be called more than once).

    Hope this helps.

    --
    - Nicholas Paldino [.NET/C# MVP]
    - mvp@spam.guard. caspershouse.co m

    "Kevin Chabot" <kevinchabot@sk ynet.be> wrote in message
    news:%23ZxalW4Z FHA.3808@TK2MSF TNGP14.phx.gbl. ..[color=blue]
    > Hi,
    >
    > I need to be able to create one or more form(s) from a method that is
    > called from different threads. When this form is created, it appears but
    > it does not receive any message. It looks blank, and when you move your
    > cursor over it, it becomes an hourglass.
    >
    > Can anyone help me with this?
    > Thanx in advance...
    >
    > Kind regards,
    > Kevin Chabot[/color]


    Comment

    • Kevin Chabot

      #3
      Re: Create forms from threads

      Hi,

      Great! Thank you very much.

      Kind regards,
      Kevin Chabot

      Nicholas Paldino [.NET/C# MVP] wrote:[color=blue]
      > Kevin,
      >
      > What you will want to do is call the Invoke method on a control that is
      > hosted on the main UI thread. This method will take a delegate and an array
      > of objects (the parameters) and call the target of that delegate in the main
      > UI thread. You would create a delegate which would point to a method which
      > creates and shows the form.
      >
      > You could also run a new message loop through a call to the static Run
      > method on the Application class in the new thread, but I would advise
      > against that (it's not common practice, and I don't think the Run method was
      > meant to be called more than once).
      >
      > Hope this helps.
      >[/color]

      Comment

      Working...