interrupting calculations

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

    #1

    interrupting calculations

    When I do a long calculation is there a possibility to interrupt this
    calculation properly?

    For i as integer = 1 to 100000000
    do something
    next

    and retrieve the i at the moment of the interrupting

    Thanks for any response


  • GhostInAK

    #2
    Re: interrupting calculations

    Hello Andreas,

    The term is: coroutine
    This article describles how to implement coroutines using the Win32 Fiber
    API: http://msdn.microsoft.com/msdnmag/is...T/default.aspx

    -Boo
    [color=blue]
    > When I do a long calculation is there a possibility to interrupt this
    > calculation properly?
    >
    > For i as integer = 1 to 100000000
    > do something
    > next
    > and retrieve the i at the moment of the interrupting
    >
    > Thanks for any response
    >[/color]


    Comment

    • Ahmed

      #3
      Re: interrupting calculations

      Do you mean this:

      dim iAfterLoop as integer

      for i as integer =1 to 10000000

      if i = something then
      iAfterloop = i
      end for
      end if
      next

      Ahmed
      andreas wrote:[color=blue]
      > When I do a long calculation is there a possibility to interrupt this
      > calculation properly?
      >
      > For i as integer = 1 to 100000000
      > do something
      > next
      >
      > and retrieve the i at the moment of the interrupting
      >
      > Thanks for any response[/color]

      Comment

      • andreas

        #4
        Re: interrupting calculations

        No, Ahmed I am thinking at the event of closing my form.

        "Ahmed" <ahmed1979@gmai l.com> wrote in message
        news:1151183649 .478586.29540@m 73g2000cwd.goog legroups.com...[color=blue]
        > Do you mean this:
        >
        > dim iAfterLoop as integer
        >
        > for i as integer =1 to 10000000
        >
        > if i = something then
        > iAfterloop = i
        > end for
        > end if
        > next
        >
        > Ahmed
        > andreas wrote:[color=green]
        > > When I do a long calculation is there a possibility to interrupt this
        > > calculation properly?
        > >
        > > For i as integer = 1 to 100000000
        > > do something
        > > next
        > >
        > > and retrieve the i at the moment of the interrupting
        > >
        > > Thanks for any response[/color]
        >[/color]


        Comment

        • GhostInAK

          #5
          Re: interrupting calculations

          Hello Andreas,

          Ah, I misunderstood as well. If yer looking for how to interrupt at form
          close, perhaps for the purpose of continuing the long op at the next run..
          it's pretty simple.

          Im the Form_QueryClose event set a varaible.. like bFormClosing to True..
          Then in the loop ask the variable if the form is closing.. and if it is,
          exit the op. (Exit For).

          -Boo
          [color=blue]
          > No, Ahmed I am thinking at the event of closing my form.
          >
          > "Ahmed" <ahmed1979@gmai l.com> wrote in message
          > news:1151183649 .478586.29540@m 73g2000cwd.goog legroups.com...[color=green]
          >> Do you mean this:
          >>
          >> dim iAfterLoop as integer
          >>
          >> for i as integer =1 to 10000000
          >>
          >> if i = something then
          >> iAfterloop = i
          >> end for
          >> end if
          >> next
          >> Ahmed
          >> andreas wrote:[color=darkred]
          >>> When I do a long calculation is there a possibility to interrupt
          >>> this calculation properly?
          >>>
          >>> For i as integer = 1 to 100000000
          >>> do something
          >>> next
          >>> and retrieve the i at the moment of the interrupting
          >>>
          >>> Thanks for any response
          >>>[/color][/color][/color]


          Comment

          • Michel Posseth  [MCP]

            #6
            Re: interrupting calculations

            Note that this aproach will only succeed if the loop is started with a
            asynchronous delegate

            Otherwise the form will simply freeze untill the loop has completed and
            pressing the close button will result in a " This program is not responding
            message "

            But for the rest you are right you can then set a boolean flag to jump out
            of the loop and let the function or a property setter return the value to
            the initial caller

            regards

            Michel Posseth [MCP]






            "GhostInAK" <ghostinak@gmai l.com> schreef in bericht
            news:c71747b418 6fb8c865fbfa858 72a@news.micros oft.com...[color=blue]
            > Hello Andreas,
            >
            > Ah, I misunderstood as well. If yer looking for how to interrupt at form
            > close, perhaps for the purpose of continuing the long op at the next run..
            > it's pretty simple.
            >
            > Im the Form_QueryClose event set a varaible.. like bFormClosing to True..
            > Then in the loop ask the variable if the form is closing.. and if it is,
            > exit the op. (Exit For).
            >
            > -Boo
            >[color=green]
            >> No, Ahmed I am thinking at the event of closing my form.
            >>
            >> "Ahmed" <ahmed1979@gmai l.com> wrote in message
            >> news:1151183649 .478586.29540@m 73g2000cwd.goog legroups.com...[color=darkred]
            >>> Do you mean this:
            >>>
            >>> dim iAfterLoop as integer
            >>>
            >>> for i as integer =1 to 10000000
            >>>
            >>> if i = something then
            >>> iAfterloop = i
            >>> end for
            >>> end if
            >>> next
            >>> Ahmed
            >>> andreas wrote:
            >>>> When I do a long calculation is there a possibility to interrupt
            >>>> this calculation properly?
            >>>>
            >>>> For i as integer = 1 to 100000000
            >>>> do something
            >>>> next
            >>>> and retrieve the i at the moment of the interrupting
            >>>>
            >>>> Thanks for any response
            >>>>[/color][/color]
            >
            >[/color]


            Comment

            • M. Posseth

              #7
              Re: interrupting calculations


              Example

              Public Class Form1
              Private Mvar_Cancell As Boolean
              Friend Property Cancell() As Boolean
              Get
              Return Mvar_Cancell
              End Get
              Set(ByVal value As Boolean)
              Mvar_Cancell = value
              End Set
              End Property
              Delegate Sub AsynchMethodInv oker()
              Private Sub Button1_Click(B yVal sender As System.Object, ByVal e As
              System.EventArg s) Handles Button1.Click
              Dim AsyncProcess As New AsynchMethodInv oker(AddressOf Me.DoSomething)
              AsyncProcess.Be ginInvoke(Nothi ng, Nothing)
              End Sub
              Private i As Integer
              Private Sub DoSomething()
              For i = 1 To 100000000
              'do your stuff here
              If Me.Cancell Then
              Exit For
              End If
              Next
              End Sub
              Private Sub Form1_FormClosi ng(ByVal sender As System.Object, ByVal e As
              System.Windows. Forms.FormClosi ngEventArgs) Handles MyBase.FormClos ing
              Me.Cancell = True
              MsgBox("The value of i =" & i.ToString)
              End Sub
              End Class


              regards

              Michel Posseth [MCP]






              "Michel Posseth [MCP]" wrote:
              [color=blue]
              > Note that this aproach will only succeed if the loop is started with a
              > asynchronous delegate
              >
              > Otherwise the form will simply freeze untill the loop has completed and
              > pressing the close button will result in a " This program is not responding
              > message "
              >
              > But for the rest you are right you can then set a boolean flag to jump out
              > of the loop and let the function or a property setter return the value to
              > the initial caller
              >
              > regards
              >
              > Michel Posseth [MCP]
              >
              >
              >
              >
              >
              >
              > "GhostInAK" <ghostinak@gmai l.com> schreef in bericht
              > news:c71747b418 6fb8c865fbfa858 72a@news.micros oft.com...[color=green]
              > > Hello Andreas,
              > >
              > > Ah, I misunderstood as well. If yer looking for how to interrupt at form
              > > close, perhaps for the purpose of continuing the long op at the next run..
              > > it's pretty simple.
              > >
              > > Im the Form_QueryClose event set a varaible.. like bFormClosing to True..
              > > Then in the loop ask the variable if the form is closing.. and if it is,
              > > exit the op. (Exit For).
              > >
              > > -Boo
              > >[color=darkred]
              > >> No, Ahmed I am thinking at the event of closing my form.
              > >>
              > >> "Ahmed" <ahmed1979@gmai l.com> wrote in message
              > >> news:1151183649 .478586.29540@m 73g2000cwd.goog legroups.com...
              > >>> Do you mean this:
              > >>>
              > >>> dim iAfterLoop as integer
              > >>>
              > >>> for i as integer =1 to 10000000
              > >>>
              > >>> if i = something then
              > >>> iAfterloop = i
              > >>> end for
              > >>> end if
              > >>> next
              > >>> Ahmed
              > >>> andreas wrote:
              > >>>> When I do a long calculation is there a possibility to interrupt
              > >>>> this calculation properly?
              > >>>>
              > >>>> For i as integer = 1 to 100000000
              > >>>> do something
              > >>>> next
              > >>>> and retrieve the i at the moment of the interrupting
              > >>>>
              > >>>> Thanks for any response
              > >>>>[/color]
              > >
              > >[/color]
              >
              >
              >[/color]

              Comment

              • GhostInAK

                #8
                Re: interrupting calculations

                Hello Michel Posseth [MCP],

                The loop could alternatively massage the message pump to keep a responsive
                UI.

                -Boo

                [color=blue]
                > Note that this aproach will only succeed if the loop is started with a
                > asynchronous delegate
                >
                > Otherwise the form will simply freeze untill the loop has completed
                > and pressing the close button will result in a " This program is not
                > responding message "
                >
                > But for the rest you are right you can then set a boolean flag to jump
                > out of the loop and let the function or a property setter return the
                > value to the initial caller
                >
                > regards
                >
                > Michel Posseth [MCP]
                >
                > "GhostInAK" <ghostinak@gmai l.com> schreef in bericht
                > news:c71747b418 6fb8c865fbfa858 72a@news.micros oft.com...
                >[color=green]
                >> Hello Andreas,
                >>
                >> Ah, I misunderstood as well. If yer looking for how to interrupt at
                >> form close, perhaps for the purpose of continuing the long op at the
                >> next run.. it's pretty simple.
                >>
                >> Im the Form_QueryClose event set a varaible.. like bFormClosing to
                >> True.. Then in the loop ask the variable if the form is closing.. and
                >> if it is, exit the op. (Exit For).
                >>
                >> -Boo
                >>[color=darkred]
                >>> No, Ahmed I am thinking at the event of closing my form.
                >>>
                >>> "Ahmed" <ahmed1979@gmai l.com> wrote in message
                >>> news:1151183649 .478586.29540@m 73g2000cwd.goog legroups.com...
                >>>> Do you mean this:
                >>>>
                >>>> dim iAfterLoop as integer
                >>>>
                >>>> for i as integer =1 to 10000000
                >>>>
                >>>> if i = something then
                >>>> iAfterloop = i
                >>>> end for
                >>>> end if
                >>>> next
                >>>> Ahmed
                >>>> andreas wrote:
                >>>>> When I do a long calculation is there a possibility to interrupt
                >>>>> this calculation properly?
                >>>>>
                >>>>> For i as integer = 1 to 100000000
                >>>>> do something
                >>>>> next
                >>>>> and retrieve the i at the moment of the interrupting
                >>>>> Thanks for any response
                >>>>>[/color][/color][/color]


                Comment

                • M. Posseth

                  #9
                  Re: interrupting calculations

                  [color=blue]
                  > The loop could alternatively massage the message pump to keep a responsive
                  > UI.[/color]

                  and so wasting proces cycles ?

                  However you are right it could work ,,, personally i would prefer ofcourse
                  my example code wich has the highest performance and is most flexible

                  regards

                  Michel Posseth [MCP]


                  "GhostInAK" wrote:
                  [color=blue]
                  > Hello Michel Posseth [MCP],
                  >
                  > The loop could alternatively massage the message pump to keep a responsive
                  > UI.
                  >
                  > -Boo
                  >
                  >[color=green]
                  > > Note that this aproach will only succeed if the loop is started with a
                  > > asynchronous delegate
                  > >
                  > > Otherwise the form will simply freeze untill the loop has completed
                  > > and pressing the close button will result in a " This program is not
                  > > responding message "
                  > >
                  > > But for the rest you are right you can then set a boolean flag to jump
                  > > out of the loop and let the function or a property setter return the
                  > > value to the initial caller
                  > >
                  > > regards
                  > >
                  > > Michel Posseth [MCP]
                  > >
                  > > "GhostInAK" <ghostinak@gmai l.com> schreef in bericht
                  > > news:c71747b418 6fb8c865fbfa858 72a@news.micros oft.com...
                  > >[color=darkred]
                  > >> Hello Andreas,
                  > >>
                  > >> Ah, I misunderstood as well. If yer looking for how to interrupt at
                  > >> form close, perhaps for the purpose of continuing the long op at the
                  > >> next run.. it's pretty simple.
                  > >>
                  > >> Im the Form_QueryClose event set a varaible.. like bFormClosing to
                  > >> True.. Then in the loop ask the variable if the form is closing.. and
                  > >> if it is, exit the op. (Exit For).
                  > >>
                  > >> -Boo
                  > >>
                  > >>> No, Ahmed I am thinking at the event of closing my form.
                  > >>>
                  > >>> "Ahmed" <ahmed1979@gmai l.com> wrote in message
                  > >>> news:1151183649 .478586.29540@m 73g2000cwd.goog legroups.com...
                  > >>>> Do you mean this:
                  > >>>>
                  > >>>> dim iAfterLoop as integer
                  > >>>>
                  > >>>> for i as integer =1 to 10000000
                  > >>>>
                  > >>>> if i = something then
                  > >>>> iAfterloop = i
                  > >>>> end for
                  > >>>> end if
                  > >>>> next
                  > >>>> Ahmed
                  > >>>> andreas wrote:
                  > >>>>> When I do a long calculation is there a possibility to interrupt
                  > >>>>> this calculation properly?
                  > >>>>>
                  > >>>>> For i as integer = 1 to 100000000
                  > >>>>> do something
                  > >>>>> next
                  > >>>>> and retrieve the i at the moment of the interrupting
                  > >>>>> Thanks for any response
                  > >>>>>[/color][/color]
                  >
                  >
                  >[/color]

                  Comment

                  Working...