Find out if a Thread was stopped via Suspend

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Ford Prefect alias Armin

    Find out if a Thread was stopped via Suspend



    I want to start a Thread and wait till the Thread has been stopped (via
    Suspend)

    How to do this.

    Sub Test

    Start Thread
    Wait Till Stopped
    Go on with this code as sone as the Thread has stopped.

    End Sub

    I know it looks like "Why does he use threads for this ?" but I need it that
    way...




  • One Handed Man [ OHM ]

    #2
    Re: Find out if a Thread was stopped via Suspend

    what does this tell you when the thread is stopped?

    Thread.CurrentT hread.IsAlive()
    OHM#


    Ford Prefect alias Armin wrote:[color=blue]
    > I want to start a Thread and wait till the Thread has been stopped
    > (via Suspend)
    >
    > How to do this.
    >
    > Sub Test
    >
    > Start Thread
    > Wait Till Stopped
    > Go on with this code as sone as the Thread has stopped.
    >
    > End Sub
    >
    > I know it looks like "Why does he use threads for this ?" but I need
    > it that way...[/color]

    Regards - OHM# OneHandedMan@BT Internet.com


    Comment

    • Herfried K. Wagner [MVP]

      #3
      Re: Find out if a Thread was stopped via Suspend

      * "Ford Prefect alias Armin" <Armin@humsoft. com> scripsit:[color=blue]
      > I want to start a Thread and wait till the Thread has been stopped (via
      > Suspend)[/color]

      Maybe with the thread's 'ThreadState' property or 'IsAlive' property.

      --
      Herfried K. Wagner [MVP]
      <http://www.mvps.org/dotnet>

      Comment

      • Codemonkey

        #4
        Re: Find out if a Thread was stopped via Suspend

        If you want to wait until the thread has finished, use Thread.Join. Waiting
        until it has been suspended is slightly more difficult.

        If the thread only suspends itself, use an "AutoResetEvent " object to signal
        the waiting thread that it has been suspended. However, if any other thread
        can suspend it, use a loop in your main thread and check the "ThreadStat e"
        property of the thread you're watching.

        e.g.


        Sub Test

        Start Thread

        do until (Thread.ThreadS tate = Suspended) orelse (Thread.ThreadS tate =
        Stopped)
        Sleep my thread to release processer in the loop
        loop

        Go on with this code as soon as the Thread has stopped.

        End Sub


        There are better ways of doing this (e.g. using Reset Events and other
        signalling methods), but they involve a little bit more code than this
        example.

        Hope this helps,

        Trev.



        "Ford Prefect alias Armin" <Armin@humsoft. com> wrote in message
        news:bqsjoa$91l $00$1@news.t-online.com...[color=blue]
        >
        >
        > I want to start a Thread and wait till the Thread has been stopped (via
        > Suspend)
        >
        > How to do this.
        >
        > Sub Test
        >
        > Start Thread
        > Wait Till Stopped
        > Go on with this code as sone as the Thread has stopped.
        >
        > End Sub
        >
        > I know it looks like "Why does he use threads for this ?" but I need it[/color]
        that[color=blue]
        > way...
        >
        >
        >
        >[/color]


        Comment

        • Ford Prefect alias Armin

          #5
          Re: Find out if a Thread was stopped via Suspend

          Thanx :-)

          I want to do this:
          [color=blue][color=green]
          > > Sub Test
          > >
          > > Start Thread
          > > Wait Till Stopped
          > > Go on with this code as sone as the Thread has stopped.
          > >
          > > End Sub[/color][/color]

          if I use Thread.CurrentT hread.IsAlive then I have to do a do .. loop or
          something because I do not want that the Code is going on untill the Thread
          is
          stopped.

          What can I do to not use a do loop (because then my whole machine is
          blocked....)


          The Problem is that I wanted to do some kind of interaction in Web.

          In Web the Code runs on the Server.

          So If you need Input from the Client you always have to go back to the
          Client.


          The started Thread calls a DLL of a User which uses our API Function.
          The User call a function from our DLL.
          This function returns a Inoput from the Client Side........

          I have to possibilities to do this.

          The easy one:

          Using Events.

          But then the Logic of the User DLL has to be cut in to parts.

          The luxourious one:

          Running the UserDLL Sub as a Thread.
          Then the Developer User calling our API Function (GetMeInputfrom TheUser)
          If in the API Funtion I abort the Thread.
          Now the Routine that started the thread should go one with running
          and get back to the client.

          The Client makes the input, sends it back to the server.
          I continue the Thread give the UserDLL the Input
          and the User DLL rubns on with it's code.


          An easier way where to do it without threads and
          make some kind of Child request to the Client.....
          But I don't know how to do this and somebody tells me this is not
          possible.....





          "One Handed Man [ OHM ]" <terry_burnsREM OVE%FOR%NO%SPAM @BTOpenworld.co m>
          schrieb im Newsbeitrag news:%239WjYu$u DHA.3196@TK2MSF TNGP11.phx.gbl. ..[color=blue]
          > what does this tell you when the thread is stopped?
          >
          > Thread.CurrentT hread.IsAlive()
          > OHM#
          >
          >
          > Ford Prefect alias Armin wrote:[color=green]
          > > I want to start a Thread and wait till the Thread has been stopped
          > > (via Suspend)
          > >
          > > How to do this.
          > >
          > > Sub Test
          > >
          > > Start Thread
          > > Wait Till Stopped
          > > Go on with this code as sone as the Thread has stopped.
          > >
          > > End Sub
          > >
          > > I know it looks like "Why does he use threads for this ?" but I need
          > > it that way...[/color]
          >
          > Regards - OHM# OneHandedMan@BT Internet.com
          >
          >[/color]



          Comment

          • Ford Prefect alias Armin

            #6
            Re: Find out if a Thread was stopped via Suspend


            To let main Thread spleeping in the Loop is a good idea !!!

            Thanx :-)


            "Codemonkey " <hunter_trev@ho tmail.com> schrieb im Newsbeitrag
            news:%23VX50JAv DHA.540@tk2msft ngp13.phx.gbl.. .[color=blue]
            > If you want to wait until the thread has finished, use Thread.Join.[/color]
            Waiting[color=blue]
            > until it has been suspended is slightly more difficult.
            >
            > If the thread only suspends itself, use an "AutoResetEvent " object to[/color]
            signal[color=blue]
            > the waiting thread that it has been suspended. However, if any other[/color]
            thread[color=blue]
            > can suspend it, use a loop in your main thread and check the "ThreadStat e"
            > property of the thread you're watching.
            >
            > e.g.
            >
            >
            > Sub Test
            >
            > Start Thread
            >
            > do until (Thread.ThreadS tate = Suspended) orelse (Thread.ThreadS tate[/color]
            =[color=blue]
            > Stopped)
            > Sleep my thread to release processer in the loop
            > loop
            >
            > Go on with this code as soon as the Thread has stopped.
            >
            > End Sub
            >
            >
            > There are better ways of doing this (e.g. using Reset Events and other
            > signalling methods), but they involve a little bit more code than this
            > example.
            >
            > Hope this helps,
            >
            > Trev.
            >
            >
            >
            > "Ford Prefect alias Armin" <Armin@humsoft. com> wrote in message
            > news:bqsjoa$91l $00$1@news.t-online.com...[color=green]
            > >
            > >
            > > I want to start a Thread and wait till the Thread has been stopped (via
            > > Suspend)
            > >
            > > How to do this.
            > >
            > > Sub Test
            > >
            > > Start Thread
            > > Wait Till Stopped
            > > Go on with this code as sone as the Thread has stopped.
            > >
            > > End Sub
            > >
            > > I know it looks like "Why does he use threads for this ?" but I need it[/color]
            > that[color=green]
            > > way...
            > >
            > >
            > >
            > >[/color]
            >
            >[/color]


            Comment

            • Codemonkey

              #7
              Re: Find out if a Thread was stopped via Suspend

              > To let main Thread spleeping in the Loop is a good idea !!!

              It's not a good idea - it's a lazy one ;)

              If you have a bit of time on your hands, read up a bit more on thread
              synchronization techniques (Monitors, Auto and Manual Reset Events etc.).
              It'll not only give you a better understanding of threading, but it will
              make your code a bit more robust and efficient than a simple loop.

              Here's some links that may be of use to you:



              Hope this helps,

              Trev.


              "Ford Prefect alias Armin" <Armin@humsoft. com> wrote in message
              news:bqsoil$rde $04$1@news.t-online.com...[color=blue]
              >
              > To let main Thread spleeping in the Loop is a good idea !!!
              >
              > Thanx :-)
              >
              >
              > "Codemonkey " <hunter_trev@ho tmail.com> schrieb im Newsbeitrag
              > news:%23VX50JAv DHA.540@tk2msft ngp13.phx.gbl.. .[color=green]
              > > If you want to wait until the thread has finished, use Thread.Join.[/color]
              > Waiting[color=green]
              > > until it has been suspended is slightly more difficult.
              > >
              > > If the thread only suspends itself, use an "AutoResetEvent " object to[/color]
              > signal[color=green]
              > > the waiting thread that it has been suspended. However, if any other[/color]
              > thread[color=green]
              > > can suspend it, use a loop in your main thread and check the[/color][/color]
              "ThreadStat e"[color=blue][color=green]
              > > property of the thread you're watching.
              > >
              > > e.g.
              > >
              > >
              > > Sub Test
              > >
              > > Start Thread
              > >
              > > do until (Thread.ThreadS tate = Suspended) orelse[/color][/color]
              (Thread.ThreadS tate[color=blue]
              > =[color=green]
              > > Stopped)
              > > Sleep my thread to release processer in the loop
              > > loop
              > >
              > > Go on with this code as soon as the Thread has stopped.
              > >
              > > End Sub
              > >
              > >
              > > There are better ways of doing this (e.g. using Reset Events and other
              > > signalling methods), but they involve a little bit more code than this
              > > example.
              > >
              > > Hope this helps,
              > >
              > > Trev.
              > >
              > >
              > >
              > > "Ford Prefect alias Armin" <Armin@humsoft. com> wrote in message
              > > news:bqsjoa$91l $00$1@news.t-online.com...[color=darkred]
              > > >
              > > >
              > > > I want to start a Thread and wait till the Thread has been stopped[/color][/color][/color]
              (via[color=blue][color=green][color=darkred]
              > > > Suspend)
              > > >
              > > > How to do this.
              > > >
              > > > Sub Test
              > > >
              > > > Start Thread
              > > > Wait Till Stopped
              > > > Go on with this code as sone as the Thread has stopped.
              > > >
              > > > End Sub
              > > >
              > > > I know it looks like "Why does he use threads for this ?" but I need[/color][/color][/color]
              it[color=blue][color=green]
              > > that[color=darkred]
              > > > way...
              > > >
              > > >
              > > >
              > > >[/color]
              > >
              > >[/color]
              >
              >[/color]


              Comment

              • Cor

                #8
                Re: Find out if a Thread was stopped via Suspend

                Hi Armin (Ford Prefect)
                [color=blue]
                > I want to start a Thread and wait till the Thread has been stopped (via
                > Suspend)[/color]

                What is the reason for starting a thread and really totaly stop the main
                thread?

                That gives only slower performance and no goals at all.

                It makes me curious.

                Cor


                Comment

                Working...