I want to close the background thread when user click power off button.
The main screen is disappear when the button is clicked later the browser screen is appear.
how to stop the Ui background thread .
and
what's the keycode for power off button on blackberry.?
pls reply me...
Try to use (char) Keypad.KEY_END keycode to catch power off button click.
In thread you can use boolean isCancelled flag with some while and if in thread code to interrupt it by setting true value. See Using Threads in J2ME Applications. Remember to clean up thread connections
Related
What is the best way to update FMX control without using Apllication.Processmessages method, וn main form.
Apllication.Processmessages call can cause to unwanted asynchrony user events to come in before operation completed.
We have old delphi XE5 in ms windows 10, i tried repaint and invalidate but it not help.
Have the OnClick handler disable the button, start a background thread/task to do the actual work, show the "please wait" message, and then exit the OnClick handler. Do not block the main thread at all. Let it run so it can process UI work normally as needed.
When your background work is finished, have the thread/task notify the main thread, which can then dismiss the "please wait" message and re-enable the button.
DO NOT do the actual work in the OnClick handler itself, and DO NOT call Application.ProcessMessages() at all.
Consider the following case:
Main Thread -----UIView info \ --------------------------------------- / Button Updated ------
\ (Some Event) / (Some Event)
\ /
BG Thread ---------------------Validate UIView info-----Update Button------------------------
On the main thread, a UIView is present
UIView makes a dispatch call is made to a background thread
In the BG Thread, the UIView's info is validated.
BG Thread makes a dispatch call to a UIButton on the main thread to update it.
My question is - notice how there is a gap between UIView info and the UIButton which means that the app could technically be updated during this time. How can I possible stop this gap? Essentially, from the BG thread, block the Main Thread till the call comes back?
You cannot and must never block the main thread. If you do, the interface will freeze and, if the blockage lasts too long, the WatchDog process will kill your app dead before the user's very eyes.
You can give the user a sense that something is going on, and discourage the user from doing anything, by, say, turning off user interaction and putting up a spinner. But in general, yes, multithreading is hard; you must be prepared for the possibility that you will come back onto the main thread when the app has changed state.
Rather than block a main thread, disable user input controls in your view until the validation is complete, then re-enable them.
It would also make sense to add an activity indicator with hidesWhenStopped set to true; it will show the user that there's background work in progress if you start it when the background work starts, and stop it when validation is complete.
If there's ever a chance the background process could hang or take longer, e.g. if it's making a network request, you might show/enable a cancel button and a way to terminate it.
Showing activity indicator and possibly providing a cancel button both require that the main thread keep running, so definitely don't block it!
Your button should not be updated in the background. You should always modify UIKit components on the main thread.
You should also never block the main thread, what you're looking for is the show the user an indication that a background process is active. 'UIActivityIndicatorView' might be a good thing to show the user, you could also disable user interaction on the view to prevent the user from touching anything if it's critical for them to wait until the operation is complete but not recommended.
Yes, you should never block the main thread and update UI only on main thread.
That said - show a spinner / activity indicator while busy on the background.
Think carefully about the UI and e.g. present something so the user can not change something while you are busy with e.g. dialog or popover or something like that.
In practise this often becomes more a question of UX than blocking.
Is it possible to somehow get a callback when the user presses on the physical power button on iOS? Just to make sure, I am not actually trying to change the behaviour of the power button, I just need to know when it was pressed.
Here is some extra info to explain why I need this callback. Our app uses a guided access mode to lock students in test and although guided access allows locking the device via the power button, that lock, unfortunately, causes our sockets to disconnect so we do not allow that. So what I need now is to detect the power button press so I can implement a fake lock in our app where I will dim the display and show a black image on top to save some battery power.
Suppose you include a pascal scripting IDE in your application and a script is created that generates a modal form with a button on it and in the button onclick event, you place a debugger breakpoint.
The result, when that button is pressed, will be a deadlocked program that only task manager can kill.
Obviously you don't want to do that, but it would be difficult to control what end users do.
So I was wondering if there was any way to suspend connected modal forms when the pascalscript debugger breakpoint was hit.?
You cannot suspend window modality. It's not a flag.
Modal window runs its own message pump. Which is many levels up in a call stack from the event handler. You cannot change call stack.
i have a direct x c++ game. i use my own mouse icon and capture the mouse and keyboard when the game initialises but the problem is that if i minimise the game and select another window, for example to skip a song media player when i go back to my game screen the mouse no longer works.
as far as i understand it i need to re capture the mouse handler every time the application gets focus but how do i do this.
can i simply re use the same mouse code from the initialisation and if so where do i put it to make it run when the application regains focus.
fyi my game runs in both windowed mode and full screen would this make a difference.
thank you
First of all, I would advise to use the Windows cursor API instead of drawing the mouse yourself. It will be much more responsive (not suffering from low fps etc.) and it is much easier to handle. You can use animated cursors this way too.
For capturing the mouse, you can only really capture it while a mouse button is pressed. If no button is pressed and the mouse is moved outside the application window, you lose the capture.
Why do you even need to capture the mouse? You get WM_MOUSEMOVE messages etc. when the mouse is not captured.