473,386 Members | 1,827 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

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
Jun 24 '06 #1
8 1202
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
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

Jun 24 '06 #2
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


Jun 24 '06 #3
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

Jun 25 '06 #4
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

Jun 25 '06 #5
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


Jun 25 '06 #6

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
>



Jun 26 '06 #7
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" <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
>

Jun 26 '06 #8
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]
"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" <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
>>


Jun 27 '06 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: androtech | last post by:
Hello, I'm looking for a function that returns a date range for a specified week number of the year. I'm not able to find functions like this anywhere. Any pointers/help would be much...
4
by: Targa | last post by:
Trying to total some price fields in a form but doesnt work when all the referenced form fields dont exisit. This is for an invoice - pulled prom a database and the form doesnt always contain the...
11
by: lduperval | last post by:
Hi, I`m trying to do date calculations in three types of time zones: local, GMT and specified. The issue I am facing is that I need to be able to specify a date in the proper time zone, and I`m...
3
by: brian kaufmann | last post by:
Hi, I had sent this earlier, and would appreciate any suggestions on this. I need to make calculations for unemployment rate for three different data sources (A,B,C) for many countries and age...
3
by: John M | last post by:
Hi, I've been coming up against a failure of a report to display the result of a simple calculation. I have realised that this calculation cannot take place unless the field I am working on is...
0
by: SJM | last post by:
There is a database which has combo boxes to allow users to select values from pre-set lists of common specifications. The form allows users to enter values that are not in the dropdown lists....
13
by: fredrik.ryde | last post by:
Hi, I have a database which contains alot of finacial data. I want to retreive some data, run som calculations with it, nothing complex just simple arithmetic. I wonder if it's faster to let...
1
by: Grubsy4u | last post by:
Grubsy4u Newbie 7 Posts October 5th, 2007 11:31 AM #1 Report calculations --------------------------------------------------------------------------------
9
Catalyst159
by: Catalyst159 | last post by:
I have a form which is used to calculate residential Floor Area Ratio (FAR). The form is structured into seven parts as follows: Part A: Maximum FAR and Floor Area: Part B: Gross Floor Area of...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.