I'm considering using Quartz for an app but I need to get called back also when a triggered event ends (e.g. at the beginning I want to start and at the end to stop something). Is it possible? Thanks.
you can get notified with TriggerListener and JobListener
Related
I'm just starting with Unity and got pretty excited when I saw that the Event System existed, and I could create custom events. The event I need is 'IInventoryMessage::NewItemInInventory', so I went ahead and created the interface for that, set it up on my Inventory.
Then it came time to trigger the event, and the documentation threw me a little.
ExecuteEvents.Execute<IInventoryMessage>(target, null, (x,y)=>x.NewItemInInventory());
My confusion is that it seems to be passing in the target.
My hope was the Unity would keep track of all the components with the message's interface and call that when it was executed. But it seems I have to pass in the GameObject myself.
Is it the case that I'm supposed to keep a list of all the GameObjects I want to receive the message, and the loop over them to pass them into Execute? Why do I need the EventSystem at that point, if I'm already looping over the objects I know need to be called?
I use ExecuteEvents only inside my custom input system where the target it's always known and up to date (according to the pointer raycast). Whenever I want to send a message or trigger an action when something happened, I use the standard C# events, as BugFinder said.
MATLAB UI callbacks (e.g. WindowKeyPressFcn) can be interrupted by newly triggered callbacks. This is very useful for terminating code which is taking too long to run. Is there any way to programmatically trigger a callback event?
Note that, in contrast to the answers to this question, I am not asking how to run a callback function programmatically. I actually want to trigger the callback event programmatically, to make use of this interruptibility feature.
Callback interruption is initiated by other callbacks specifically because there can't be any other code executing while the callback is executing. If you're in a position to "programmatically" invoke a callback, you already have "interrupted" any other callback that might be in progress.
That isn't to say that you can't trigger UI callbacks programmatically. Callback handles stored in object properties like WindowKeyPressFcn generally feed into listeners for corresponding events for those objects. For example you can invoke WindowKeyPressFcn for the current figure using notify(gcf,'WindowKeyPress').
However if you're in a position to make that call, you can also do anything you'd like to in the interrupting callback. If you're able to run that line because you are interrupting a callback, you then need to consider what the callback will do when it resumes execution.
I'm working on a small project in which I need to execute a LOOP to ask questions, and during the LOOP I need to wait for the answer from user before I can perform the next operation.
Any of you could help?
The iPhone's object-oriented framework, Cocoa Touch, already includes the loop you need. There's a class called NSRunLoop that does exactly what you require: it waits for events from the user interface (among other things) and then calls your code to handle the events.
So don't worry about building this loop yourself. Apple has a tutorial that shows how you can build an app that waits for user input and does work based on that input.
You can set all your butons into disabled state:
[myButton setUserInteractionEnabled:false];
After loop is finished, just set it back to true state. This seems to be the easiest possibility.
I have a volume slider in my application that I'd like to have a sound effect play when the user changes the value. The standard valueChanged event works well here, and I'd like to use it in conjunction with a touches ended signal to trigger the sound at the end. Is there a control event here that I'm missing that would run my method when the touches finish? It doesn't seem like there is a UIControlEventTouchesEnded...
Some code samples would help, but I guess you're looking for UIControlEventTouchUpInside. I'm not sure, if it works with a slider.
One possibility would be to set the slider's continuous to NO. Now it emits just one valueChanged event, namely when the user is all finished - just what you want to know.
I want to run a single background thread for an iPhone application which is available in background all the time and gets executed when specific event fires and go to wait for specific event to fire to start its execution again. During the execution of thread if specific event is fired again then thread should restart its work.
I am working on a custom map application. On TouchesMoved event, I need to load the map image tiles according to the positions moved in a background thread. The problem is that when I move the map with speed the touchesMoved event is fired the previous thread has not finished its work and new thread is started. It causes thread safety issue and my application is crashed.
So I am thinking of a solution to have a single thread all the time available and starts its work when touchesMoved is fired if touchesMoved is fired again it should restart its work instead of starting a new thread. I think it will prevent the thread safety issue.
Please help
Firstly I'd echo the use of NSOperation and NSOperationQueue. You could fall-back to using NSThread directly, but the point of NSOperation is that it hides threading from you, leaving you to concentrate on the processing you need to do. Try firing NSOperation requests as and when required, see what the performance is like in your use-case; even if these operations get data in an async manner, it should provide you with a cleaner solution with good performance, plus future proof.
I've successfully used NSInvocationOperation to fire requests as often as required, and it sounds like the sort-of requirements and behaviour you're after. I would suggest more generally that you experiment with these in a test project; here you can test performance.
The following weblog's helped me start playing with NSOperation:
http://www.dribin.org/dave/blog/archives/2009/09/13/snowy_concurrent_operations/
http://www.cimgf.com/2008/02/16/cocoa-tutorial-nsoperation-and-nsoperationqueue/
As always, the Apple Threading Programming Guide is a key read, to figure out which way to go depending on needs.
This sounds like an ideal job for an NSOperationQueue. Have a read of the operation queue section of the concurrency guide.
Essentially, you create an NSOperation object for each map tile load and place them on a queue that only allows them to execute one at a time.
Put a run loop in your background compute thread. Then use an NSOperation queue to manage sending messages to it. The queue plus the run loop will serialize all the work requests for you.