I have a SL 4.0 app running out of browser with full priviliges. How can I check for updates (CheckAndDownloadUpdateAsync()) every 10 minutes without affecting UI thread. I've tried using the Timer, but the CheckAndDownloadUpdateCompleted doesn't get executed. I think it is erroring out silently.
Thanks in advace...
Never mind, I have solved it by encapsulating the code within a class. I'm not sure what was breaking it, but this works. Maybe the issue was the Timer thread calling an event of the App class or something else, but now the timer calls the a method of the new class and it all works.
Thanks anyway...
Related
I am currently learning react right now. I am following a react tutorial for a stopwatch application where it just increments the time every second. The code perfectly works as it indeed increments the time every second. However, if I open a new browser tab, or even open a different application, it seems that react doesn't update the state, meaning, the timer stops incrementing the value. But if I visit the react application, it begins to increment (once again).
I literally watch the timer go to '00:00:10' and then click another tab and wait for about 10 seconds. When I go back to the react application, the timer is still at '00:00:11', instead of '00:00:20'.
Is there something I am missing? Why is react behaving this way? It is because of performance issues? I am pretty sure this is a nature of react but I can't seem to find an explanation anywhere else.
I am also not sure if I should provide the code for the stopwatch application as I am sure that it's not a bug, nor a problem relating to the code itself. Let me know if I need to include the code so that I can edit this question.
If your website isn't active (in an active browser tab) then the Browser doesn't execute your JavaScript code. It does that to save CPU time - people tend to have a lot of tabs open.
For a timer application you want to remember the timer start time (e.g. with new Date().getTime()) and then every second you calculate the difference to this start time. This way if the user leaves the tab and comes back then the timer is correct again after latest a second.
Another benefit is that your timer will be more accurate even if the browser tab remains focused all the time. The timer calls aren't exact so your code isn't called exactly every second, but only about every second and the errors sum up over time. If you have a start time available then these errors don't matter.
Edit: There is more to this topic, the best thing I could find quickly is this discussion How do browsers pause/change Javascript when tab or window is not active?
I am following an example here: https://github.com/apache/flink/blob/master/flink-streaming-java/src/main/java/org/apache/flink/streaming/api/functions/source/StatefulSequenceSource.java
I am trying to build a source using a jdbc connection which extends RichParallelFunction and implements CheckpointedFunction, as I would like to be able to save my watermark from my source tables in the case of restart.
When testing locally with docker, I can call my run() method just fine and read data from my source database, but I am not sure where the snapshotState and initializeState methods actually get called. I have logic in those methods that should be setting the value of my watermark based on first startup/recovery - I just never see that being accessed, and not sure if I should be calling the methods externally?
Thanks for the help in advance!
The methods will be called by the Flink framework when it needs to (when performing a checkpoint or a save point).
See https://nightlies.apache.org/flink/flink-docs-stable/docs/dev/datastream/fault-tolerance/state/#using-operator-state and https://nightlies.apache.org/flink/flink-docs-stable/api/java/org/apache/flink/streaming/api/checkpoint/CheckpointedFunction.html
I'm working on an app using geo fences but I'm hitting some issues.
I've been testing on Android predominantly so far.
a) I set up the geo-fence and it triggers fine for enters and exit events.
However, after an extended period time (such as a few hours or overnight) the events stop until the app is opened again.
b) My other issue is the geo-fence exit seems to trigger even when I haven't moved at all, and definitely not outside of the radius (150 meters).
I've looked at https://www.codenameone.com/javadoc/com/codename1/location/Geofence.html, and my code is very similar to the example.
Are there any other build hints I need to make it more accurate and persist in the background?
Geofencing should only be added once, it's a very flaky API in the native OS especially when it comes to background behavior that breaks frequently with OS updates.
Use something like:
if(Preferences.get("AddedGeofence", false)) {
addGeofenceBinding();
Preferences.set("AddedGeofence", true);
}
And see if this works.
I'm running a Windows Forms application that need to update the GUI, and therefore have to use the scheduler that come from the current synchronization context. Code: TaskScheduler.FromCurrentSynchronizationContext()
When writing unit tests - this scheduler need to be switched because we want to use our own scheduler that run stuff concurrently and synchronously in a test. There are alternatives (injection, ManualResetEvent) but that's ugly and we don't want it.
It is possible to modify TaskScheduler.Default by using reflection to overwrite a private variable and that's great, but there is no obvious way of doing the same with TaskScheduler.FromCurrentSynchronizationContext().
So, how do you do this?
One thing which might work when in a unit testing scenario, is to create a TestSynchronizationContext that inherits from SynchronizationContext, and assign it with SynchronizationContext.SetSynchronizationContext(). Your TestSynchronizationContext class would override Post method to instead redirect to the Send method, causing it to run synchronously.
You can find the sources here for reference.
I have a WPF application that is doing some serious work (doing some calculations) when a button is hit. I wanted to add a 'busy animation'. However, the application is so busy doing its work that the animation is stopped until the calculations are finished.
The serious work should always be handled in a separate thread otherwise the complete user interface may be blocked. So you are unable to click anything and not even close the application.
If it is possible you should also try the make small chunks of work and give the rest of the application time to "take a breath" and not do all work at once. It's not always possible but some work can be managed that way.
Are you running your "serious work" in the UI thread? If so, you need to move the work to a separate thread if you still want the UI to be updated.