Event Handling

15 Ansichten (letzte 30 Tage)
Harry MacKenzie
Harry MacKenzie am 12 Jan. 2012
My program is setup so that it can be interupted by a number of external events. These events happen randomly and I can not predict where or when the interuption will occur. The interupting events run bits of code which change state variables in my program. Once the interuption has been processed and I have returned to my regular program code, is there any way for me to know I have been interupted? I would like the code which was running before the interuption to somehow know it was interupted and that maybe it should terminate and try running again from the beginning... if it doesnt it may continue with incorrect state information and make mistakes.

Antworten (4)

Daniel Shub
Daniel Shub am 12 Jan. 2012
If you are not using timer objects, then your code will only be interrupted at well defined times, like when drawnow is called. For a complete list see http://www.mathworks.com/help/releases/R2011a/techdoc/ref/drawnow.html. If you code never flushes the event queue, then you know the state is okay.
Timer objects, however, throw this whole model out the window and exist in some separate thread that I don't think you can easily deal with: http://www.mathworks.com/matlabcentral/answers/22180-timers-and-thread-safety
You might be able to get all the timer objects at the beginning, get their execution counts, load your state data, do your processing, and then check the counts again.

Harry MacKenzie
Harry MacKenzie am 12 Jan. 2012
My Events are from an external interface (not timer driven - more like notify/listen) so no way to know when they will happen... each interupt halts my current execution randomly (not on redraws or waits etc... the event is not linked to a GUI object)... once the interupt has been processed my code returns to the point from which it was interupted and continues as if nothing had happened... i need it to know it was just interupted as it may be pointless for it to continue on.
  2 Kommentare
Daniel Shub
Daniel Shub am 12 Jan. 2012
My understanding is that if your code does something that results in a notify call (or the user initiates a callback), the event will be added to the event queue, but not processed until the event queue is flushed. The only exception that I am aware of is if the event arises from a timer object.
Harry MacKenzie
Harry MacKenzie am 12 Jan. 2012
The event orginates from an external java library... it does not queue it just breaks my code where it is and executes its callback... when the callback is finished running my code then resumes from where it left off... when i get multiple overlapping callbacks they each interupt the previous one only returning to the previous callback when the most recent one has completed...
I know gui objects have a property 'Interuptible'... i would like to implement this same feature on some of the methods of my own class.

Melden Sie sich an, um zu kommentieren.


Walter Roberson
Walter Roberson am 12 Jan. 2012

Daniel Shub
Daniel Shub am 12 Jan. 2012
Now I got it. The source of the event is coming from a Java object. Yet another way around the single threaded MATLAB system.
  1 Kommentar
Yair Altman
Yair Altman am 20 Jan. 2012
I posted an article related to this yesterday: http://undocumentedmatlab.com/blog/matlab-java-memory-leaks-performance/ - it describes both Matlab callbacks of Java events, and its relationship to timer callbacks.

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by