Home All Groups Group Topic Archive Search About

interrupting calculations

Author
24 Jun 2006 8:50 PM
andreas
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

Author
24 Jun 2006 9:02 PM
GhostInAK
Hello Andreas,

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

-Boo

Show quoteHide quote
> 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
>
Author
24 Jun 2006 9:14 PM
Ahmed
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:
Show quoteHide quote
> 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
Author
25 Jun 2006 5:22 AM
andreas
No, Ahmed I am thinking at the event of closing my form.

Show quoteHide quote
"Ahmed" <ahmed1***@gmail.com> wrote in message
news:1151183649.478586.29540@m73g2000cwd.googlegroups.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
>
Author
25 Jun 2006 7:20 AM
GhostInAK
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

Show quoteHide quote
> No, Ahmed I am thinking at the event of closing my form.
>
> "Ahmed" <ahmed1***@gmail.com> wrote in message
> news:1151183649.478586.29540@m73g2000cwd.googlegroups.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
>>>
Author
25 Jun 2006 3:14 PM
Michel Posseth [MCP]
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]






Show quoteHide quote
"GhostInAK" <ghosti***@gmail.com> schreef in bericht
news:c71747b4186fb8c865fbfa85872a@news.microsoft.com...
> 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" <ahmed1***@gmail.com> wrote in message
>> news:1151183649.478586.29540@m73g2000cwd.googlegroups.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
>>>>
>
>
Author
26 Jun 2006 8:35 AM
M. Posseth
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 AsynchMethodInvoker()
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
        Dim AsyncProcess As New AsynchMethodInvoker(AddressOf Me.DoSomething)
        AsyncProcess.BeginInvoke(Nothing, 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_FormClosing(ByVal sender As System.Object, ByVal e As
System.Windows.Forms.FormClosingEventArgs) Handles MyBase.FormClosing
        Me.Cancell = True
        MsgBox("The value of i =" & i.ToString)
    End Sub
End Class


regards

Michel Posseth [MCP]






Show quoteHide quote
"Michel Posseth  [MCP]" wrote:

> 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" <ghosti***@gmail.com> schreef in bericht
> news:c71747b4186fb8c865fbfa85872a@news.microsoft.com...
> > 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" <ahmed1***@gmail.com> wrote in message
> >> news:1151183649.478586.29540@m73g2000cwd.googlegroups.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
> >>>>
> >
> >
>
>
>
Author
26 Jun 2006 6:55 PM
GhostInAK
Hello Michel Posseth [MCP],

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

-Boo


Show quoteHide quote
> 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" <ghosti***@gmail.com> schreef in bericht
> news:c71747b4186fb8c865fbfa85872a@news.microsoft.com...
>
>> 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" <ahmed1***@gmail.com> wrote in message
>>> news:1151183649.478586.29540@m73g2000cwd.googlegroups.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
>>>>>
Author
27 Jun 2006 6:54 AM
M. Posseth
> The loop could alternatively massage the message pump to keep a responsive
> UI.

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]


Show quoteHide quote
"GhostInAK" wrote:

> Hello Michel Posseth [MCP],
>
> The loop could alternatively massage the message pump to keep a responsive
> UI.
>
> -Boo
>
>
> > 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" <ghosti***@gmail.com> schreef in bericht
> > news:c71747b4186fb8c865fbfa85872a@news.microsoft.com...
> >
> >> 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" <ahmed1***@gmail.com> wrote in message
> >>> news:1151183649.478586.29540@m73g2000cwd.googlegroups.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
> >>>>>
>
>
>