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]
"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" <gh*******@gmail.com> schreef in bericht
news:c7**************************@news.microsoft.c om... 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" <ah*******@gmail.com> wrote in message
news:11*********************@m73g2000cwd.googlegro ups.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
>