Path: news.mathworks.com!newsfeed-00.mathworks.com!newscon02.news.prodigy.net!prodigy.net!news.glorb.com!news.aset.psu.edu!news.cse.psu.edu!elk.ncren.net!newsflash.concordia.ca!canopus.cc.umanitoba.ca!not-for-mail
From: roberson@ibd.nrc-cnrc.gc.ca (Walter Roberson)
Newsgroups: comp.soft-sys.matlab
Subject: Re: Event queuing , callbacks and buttons
Date: Tue, 12 Feb 2008 22:44:08 +0000 (UTC)
Organization: National Research Council Canada - Conseil national de rechereches Canada
Lines: 38
Message-ID: <fot7fo$amv$1@canopus.cc.umanitoba.ca>
References: <forpl9$8cv$1@fred.mathworks.com> <foskje$dh1$1@canopus.cc.umanitoba.ca> <fot632$pgq$1@fred.mathworks.com>
NNTP-Posting-Host: origin.ibd.nrc.ca
X-Trace: canopus.cc.umanitoba.ca 1202856248 10975 192.70.172.160 (12 Feb 2008 22:44:08 GMT)
X-Complaints-To: abuse@cc.umanitoba.ca
NNTP-Posting-Date: Tue, 12 Feb 2008 22:44:08 +0000 (UTC)
Originator: roberson@ibd.nrc-cnrc.gc.ca (Walter Roberson)
Xref: news.mathworks.com comp.soft-sys.matlab:450970



In article <fot632$pgq$1@fred.mathworks.com>,
Johannes  <RudiRocker@gmx.net> wrote:
>What I want to do is that when the button gets hit 
>twice it should only execute the last callback and the first callback should be 
>interrupted and never continued again.

It is easier to arrange it the other way around.

Have a global flag "interrupted" that you clear before any of
the activity begins.

You get a click, you enter the callback
routine. You test the flag: if it is clear, then you fetch
the current parameter values and operate on them, checking
from time to time whether the flag is still clear. If the flag
never becomes set before you have reached the end of the calculation,
then you were not interrupted and you should finish up normally.

When you test the flag the first time upon entry into the routine
and you find it set, then you fetch the current parameter values
(CurrentPoint, gcbo, whatever you need that identifies that
click uniquely) and store them in a global variable, and you leave
the flag set and you exit.

When you test the flag in the middle of the calculation routine
and you find that it has been set, you abandon the current calculation,
head back to the top of the routine, fetch the parameter values
from the global variable, clear the flag, and start the
calculation again.

If you try to do it the other way around, cancelling the
"older" incarnations but continuing to run the newest, I think
you will find it harder to decide whether you are in the "newest"
or not.
-- 
  "Every intellectual product must be judged from the point of view
  of the age and the people in which it was produced."
                                              -- Walter Horatio Pater