Threading

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Charles A. Lackman

    Threading

    Hello,

    I am making a app that creates a thread to show a clipboard. If the
    clipboard is double clicked, another window is displayed, the event is
    handled inside the main app. What I would like to do is have the clipboard
    use the main thread of the application that called it to handle the new
    window. Is this possible and if so how would this be accomplished.


    ie.

    Form1 creates a thread and the thread displays Form2.

    Form2 when double clicked raises an event that creates a new form (Form3).
    The event is handled inside Form1.

    How can I get Form3 to be managed by the main thread (Form1)?


    Thanks,

    Chuck


  • Sijin Joseph

    #2
    Re: Threading

    If Form3 is getting created from main thread as it seems to be, then
    Form3 will be managed by the main thread only.

    Sijin Joseph



    Charles A. Lackman wrote:[color=blue]
    > Hello,
    >
    > I am making a app that creates a thread to show a clipboard. If the
    > clipboard is double clicked, another window is displayed, the event is
    > handled inside the main app. What I would like to do is have the clipboard
    > use the main thread of the application that called it to handle the new
    > window. Is this possible and if so how would this be accomplished.
    >
    >
    > ie.
    >
    > Form1 creates a thread and the thread displays Form2.
    >
    > Form2 when double clicked raises an event that creates a new form (Form3).
    > The event is handled inside Form1.
    >
    > How can I get Form3 to be managed by the main thread (Form1)?
    >
    >
    > Thanks,
    >
    > Chuck
    >
    >[/color]

    Comment

    • Herfried K. Wagner [MVP]

      #3
      Re: Threading

      "Charles A. Lackman" <Charles@Create ItSoftware.net> schrieb:[color=blue]
      > Form1 creates a thread and the thread displays Form2.
      >
      > Form2 when double clicked raises an event that creates a new form (Form3).
      > The event is handled inside Form1.
      >
      > How can I get Form3 to be managed by the main thread (Form1)?[/color]

      Create /all/ forms in the application's main (UI) thread. Only start
      "operations " in a separate thread and use
      'Control.Invoke '/'Control.BeginI nvoke' to communicate in the thread -> UI
      direction.

      --
      M S Herfried K. Wagner
      M V P <URL:http://dotnet.mvps.org/>
      V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

      Comment

      • Robby

        #4
        Re: Threading


        Let Form2 create Form3 by using a callback on Form1. This will create Form3
        on the Form1 thread.

        Robby


        "Charles A. Lackman" <Charles@Create ItSoftware.net> wrote in message
        news:ult$vl21EH A.3504@TK2MSFTN GP12.phx.gbl...[color=blue]
        > Hello,
        >
        > I am making a app that creates a thread to show a clipboard. If the
        > clipboard is double clicked, another window is displayed, the event is
        > handled inside the main app. What I would like to do is have the
        > clipboard use the main thread of the application that called it to handle
        > the new window. Is this possible and if so how would this be
        > accomplished.
        >
        >
        > ie.
        >
        > Form1 creates a thread and the thread displays Form2.
        >
        > Form2 when double clicked raises an event that creates a new form (Form3).
        > The event is handled inside Form1.
        >
        > How can I get Form3 to be managed by the main thread (Form1)?
        >
        >
        > Thanks,
        >
        > Chuck
        >[/color]


        Comment

        • Charles A. Lackman

          #5
          Re: Threading

          Hello and thank you for your assistance.

          I have attempted to accomplish what I need using delegates with no success.
          i.e.

          //Button Click//
          Dim PollThread As Threading.Threa d
          PollThread = New Threading.Threa d(AddressOf PollThreadAddre ss)
          PollThread.Star t()
          End Sub

          Private Sub PollThreadAddre ss()
          frm1PollDatabas e.TopMost = True
          frm1PollDatabas e.ShowDialog()
          End Sub

          //Button Click inside frm1PollDatabas e that raises an event inside the
          Parent Form//
          Delegate Sub FromMyPage()
          Dim MyDeleg As FromMyPage

          Private Sub ApplyMyPage
          MyDeleg = New FromMyPage(Addr essOf DelegateFromMyP age)
          MyDeleg.Invoke( )
          End Sub

          Private Sub DelegateFromMyP age()
          frm1Modify.show dialog
          End Sub

          ** frm1PollDatabas e is created inside a new thread and must always be on
          top, which works fine. But when the user wants to send that data from this
          form to a new form (frm1Modify) the form is displayed but frm1PollDatabas e
          becomes disabled because of the Showdialog method. I cannot use show for
          this form to be displayed. If the original thread (Main) displays this form
          wont it prevent this problem? The above code did not keep frm1PollDatabas e
          from being disabled.

          Thanks Again,
          Chuck


          "Charles A. Lackman" <Charles@Create ItSoftware.net> wrote in message
          news:ult$vl21EH A.3504@TK2MSFTN GP12.phx.gbl...[color=blue]
          > Hello,
          >
          > I am making a app that creates a thread to show a clipboard. If the
          > clipboard is double clicked, another window is displayed, the event is
          > handled inside the main app. What I would like to do is have the
          > clipboard use the main thread of the application that called it to handle
          > the new window. Is this possible and if so how would this be
          > accomplished.
          >
          >
          > ie.
          >
          > Form1 creates a thread and the thread displays Form2.
          >
          > Form2 when double clicked raises an event that creates a new form (Form3).
          > The event is handled inside Form1.
          >
          > How can I get Form3 to be managed by the main thread (Form1)?
          >
          >
          > Thanks,
          >
          > Chuck
          >[/color]


          Comment

          • Robby

            #6
            Re: Threading


            Instead of threading could you just show as a normal top most form? When
            the selection is made on frm1PollDatabas e raise an event on the main form.
            You could then create frm1Modify on the main form, fill it with the
            properties needed from frm1PollDatabas e, destroy frm1PollDatabas e and then
            show frm1Modify. Now the main form and frm1Modify are on the same thread
            and can communicate easily while they do their own processes. This seems to
            do the trick without all the unecessary threading.

            Is there any reason why you have to thread?

            Robby


            "Charles A. Lackman" <Charles@Create ItSoftware.net> wrote in message
            news:%238VnoF91 EHA.1192@tk2msf tngp13.phx.gbl. ..[color=blue]
            > Hello and thank you for your assistance.
            >
            > I have attempted to accomplish what I need using delegates with no
            > success. i.e.
            >
            > //Button Click//
            > Dim PollThread As Threading.Threa d
            > PollThread = New Threading.Threa d(AddressOf PollThreadAddre ss)
            > PollThread.Star t()
            > End Sub
            >
            > Private Sub PollThreadAddre ss()
            > frm1PollDatabas e.TopMost = True
            > frm1PollDatabas e.ShowDialog()
            > End Sub
            >
            > //Button Click inside frm1PollDatabas e that raises an event inside the
            > Parent Form//
            > Delegate Sub FromMyPage()
            > Dim MyDeleg As FromMyPage
            >
            > Private Sub ApplyMyPage
            > MyDeleg = New FromMyPage(Addr essOf DelegateFromMyP age)
            > MyDeleg.Invoke( )
            > End Sub
            >
            > Private Sub DelegateFromMyP age()
            > frm1Modify.show dialog
            > End Sub
            >
            > ** frm1PollDatabas e is created inside a new thread and must always be on
            > top, which works fine. But when the user wants to send that data from
            > this form to a new form (frm1Modify) the form is displayed but
            > frm1PollDatabas e becomes disabled because of the Showdialog method. I
            > cannot use show for this form to be displayed. If the original thread
            > (Main) displays this form wont it prevent this problem? The above code
            > did not keep frm1PollDatabas e from being disabled.
            >
            > Thanks Again,
            > Chuck
            >
            >
            > "Charles A. Lackman" <Charles@Create ItSoftware.net> wrote in message
            > news:ult$vl21EH A.3504@TK2MSFTN GP12.phx.gbl...[color=green]
            >> Hello,
            >>
            >> I am making a app that creates a thread to show a clipboard. If the
            >> clipboard is double clicked, another window is displayed, the event is
            >> handled inside the main app. What I would like to do is have the
            >> clipboard use the main thread of the application that called it to handle
            >> the new window. Is this possible and if so how would this be
            >> accomplished.
            >>
            >>
            >> ie.
            >>
            >> Form1 creates a thread and the thread displays Form2.
            >>
            >> Form2 when double clicked raises an event that creates a new form
            >> (Form3). The event is handled inside Form1.
            >>
            >> How can I get Form3 to be managed by the main thread (Form1)?
            >>
            >>
            >> Thanks,
            >>
            >> Chuck
            >>[/color]
            >
            >[/color]


            Comment

            Working...