I've a background task for my universal app with a TimeTrigger. It works fine, but the TimeTrigger class only has a freshnessTime for reoccuring tasks. I would prefer if the background task was executed once sometime at night. Is that possible somehow? I've search around as good as I can without finding anything, but perhaps I missed something. For now I'm setting freshnessTime to 720 (60*12) to have it execute twice a day:
var builder = new BackgroundTaskBuilder {Name = TASK_NAME, TaskEntryPoint = TASK_ENTRY};
builder.SetTrigger(new TimeTrigger(720, false));
var registration = builder.Register();
Seems that the best way to do this is to run the tasks the background is supposed to do (like updating a live tile) when your app is loaded/running and then do time-triggers twice per day as the code example in the question shows.
Related
I am working on html2canvas with vue based app
html2canvas(document.querySelector("#interactivecanvas")).then(canvas => {
//document.body.appendChild(canvas)
let image_data = canvas.toDataURL("image/png");
image_data = image_data.replace('data:image/png;base64,', '');
});
The code above is working, however when the code is executing the vue app will get stuck which I can't manipulate other UI components unless the html2canvas finishes the process. Additionally I always have to wait a while for the process to complete and then upload the data to server, which is too tedious and time-consuming.
How would I bypass the problem, like using another worker to process it??
Moreover, I am wondering is it possibl to process it in the background with a queue of tasks because I don't want to manually repeating the process of waiting and updating?
I have been working on a html-website lately. The website is a web-app made to measure time spent on a project and to map your efficiency per hour of the day.
I have tested this website while looking at the website, and it worked fine. It is that I have just recently added a part where it will map your time over the day, and since I had to wait for 5 minutes while the clock was passing a 5 minute treshhold, I figured that it would be efficient to do some other things while letting the clock do its thing.
Unfortunately I was kind of shocked to see that the clock had not changed even a millisecond, and that has to be because the js-interval was not continued when viewing a different chrome tab. Once I opened the clock it continued where it was left once I switched tabs.
Now my question is:
Is there a way to let the HTML-website run in the background, just like a background-application, so you can do other tasks while the website will continue it's interval?
Chrome manages to save resources from tabs which are in background, so when you call setTimeout or setInterval - it still runs but not more than 1 call in a second. So if your code tried to call setTimeout 1,000,000 times, you will wait next 1,000,000 seconds until all calls will be completed. And sometimes you don't realize, that some animation calls setTimeout many-many times for many animated objects :-)
The way of implementing what you need - is to abstract from timeouts and calculate time difference from last call.
Example:
let lastMesure = Date.now();
let workTime = 0;
setInterval(() => {
const now = Date.now();
workTime += (now - lastMeasure);
lastMeasure = now;
}, anyTimePeriod);
It will sleep most of the time when tab is in background, but when you switch back to the tab - first calculation will get you back to right value.
Im currently working on an integration where the external service returns json strings.
Some of the strings are quite long, and im just wondering if anyone knows of a plugin that can be used to count down how long a total request takes.
I know i could run a timer on the server to monitor how long the request takes, but what im hoping to see is if there is a way to time the entire experience within a browser so I can see how long it takes to request content and display the end result (the webpage) to a user ?
thanks in advance
As pointed out, you can use the Network tab of Developer Tools to see the timeline, from which you can check the request times and data size of any requested resource within the lifetime of your page.
Alternatively, if what you mean is that you need to have access to the time from within your code, you can measure the time between issuing the request and receiving the response. Something like this should suffice.
var start = Date.now();
http.request(resourceUrl, function(data) {
var stop, duration;
stop = Date.now();
duration = stop - start;
// duration of request in ms
doSomething(data);
});
We are using a Cumulus server as our RTMFP server to implement a voice chat.
The voice streaming with NetStreams works perfectly fine almost no delay here, but we also want to transfer the activity level of the microphone of each member of the NetGroup.
So we tried transferring the data using NetGroup.post(data). That worked well, but had a delay of ~500ms even when testing with multiple clients on the same machine!
Obviously, half a second in microphone activity is just waaay to much delay to display it in any way.
Now we are trying to use direct routing with NetGroup.sendToAllNeighbors(, but it simply does nothing. I have read all the documentation on it and normally a NetGroup status event with "NetGroup.SendTo.Notify" should be triggered on the receiving clients. Instead, nothing happens.
Here is the code, which is called each frame:
var tsObject :TimestampedObject = new TimestampedObject();
tsObject.timestamp = (new Date()).getTime();
tsObject.sender = _netConnection.nearID;
tsObject.object = _mic.activityLevel;
_netGroup.sendToAllNeighbors(tsObject);
I know each frame is a bit much, but for now it is just a test case.
What are we doing wrong? As I said, voice communication itself works fine. As does Netgroup.post(data), which is just way too slow to use for this use case.
I have a swf that I would like to cookie to control the frame the user see's depending on whether it is a first time site visit or returned visit. My code is below - it works, it doesn't bring back any out messages however when I load the swf into my site that uses this technique the page becomes extremely slow and unresponsive - can anyone help out with any reasons why this may occur?
var my_so:SharedObject = SharedObject.getLocal("visited", "/");
if (my_so.data.newVisitor != undefined) {
//object exists: return user
this.gotoAndPlay(2);
} else {
//object doesn't exist: new user
my_so.data.newVisitor = "no";
this.gotoAndStop(1);
}
Many thanks in advance
Rachel
SharedObjects in general are extremely slow in Flash. That being said, there is no reason why it should be slowing down your entire site after it has been used.
When writing to a SO, you have to use flush() to tell Flash to actually write the data.
my_so.data.newVisitor = "no";
// Write the data to disk
my_so.flush();
Another thing to try would be to actively close the connection after you are done with it. So after the else statement you would add:
// Close the connection
my_so.close();
// Clear pointer for GC
my_so = null;
If that doesn't work, the next steps would be to put trace statements in and around the SOs and make sure they aren't being accessed while the program is running.