Im trying to figure out how can I do a live 30 second timer which every 30 second something happens. No matter who opens the app the timer will continue to run even if you just open the app and the timer might be on 20s or 10s or even 1s. And right when it hits zero, I have something that pops up.
I have it done but it's a timer that starts when the app is view is opened and always starts from 30s and if someone else opens the app he also starts from 30s i want it so that who ever opens the view the timer is still running.
Related
What is included in "Idle" and "Other" times into Sumary of Timeline tab in Chrome Developer Tools?
What causes so much inaction?
Why do these occur?
How to reduce these times? Is it possible?
Why the browser is inactivity for so long (in the context of idle time)?
At the beginning of more than 1.8 seconds nothing happens:
In the middle the "Idle" and the "Other" occupy about 0.3 seconds:
At the end of almost 3 seconds nothing happens:
In this example, we have almost five seconds of inactivity browser...
The "Idle" state occurs when the browser has not yet completed the final rendering of the page on the screen but must put the process on hold while waiting for missing data or resources needed to resume and complete it.
We can deal with long "Idle" periods, for example, when the browser waits for a synchronous response, which is generated for a long time on the server-side.
The "Idle" state should not be confused with the "Loading" state, which is the time the browser actually uploads the response (from the first to the last byte), not the time from sending the request to uploading the response.
The "Other" state represents the time of all browser activities other than those listed in the pie chart, such as DOM tree building, CSSOM and others.
This issue is partly explained on the "Render-tree Construction, Layout, and Paint" website.
I found part of the answer on Addy Osmani's blog:
In Frame mode, the shaded vertical bars correspond to recalculating styles, compositing and so on. The transparent areas of each vertical bar correspond to idle time, at least, idle on the part of your page. For example, say your first frame takes 15ms to execute and the next takes 30ms. A common situation is that frames are synchronized to refresh rate and in this case, the second frame took slightly longer than 15ms to render. Here, frame 3 missed the "true" hardware frame and was rendered upon the next frame, hence, the length of the second frame was effectively doubled.
But this does not exhaust the topic.
Example from which the chart included in the question did not use frames.
I still do not know how to shorten the time, and what is hidden under "Other".
Check out this topic
Idle is just that, nothing was going on so nothing to worry about as far as I know.
Other is "un-instrumented activity". Which is stuff that currently isn't able to be broken down. So, you can't analyze what was going on in there from the DevTools.
Using Start profilling and reload page button instead of Record button will give the results we are waiting, since it stops recording after page to finish the loading, reducing idle.
I have a timer that runs to restart an alarm once it goes off.
alarm = NSTimer.scheduledTimerWithTimeInterval(
60 * minutesConstant + secondsConstant,
target:self,
selector: Selector("endSession"),
userInfo: nil,
repeats:false)
Its selector function sets a mode flag, and calls the original function that set the alarm with new minutes and seconds constants, and also sends a user notification that the session has restarted.
I have a menu item that gets updated with the remaining time
So I've been opening it to check that my alarm does indeed restart, and that the notification shows once it hits zero. It works, but when I have the menu open and it gets down to zero it just stays at 0:00 and the timer doesn't fire until I click off the menu at which point it immediately shows the notification and resets the timer like intended.
How can I force the timer to fire when the menu is open? It's not a big deal but I don't want the user to be confused with the session just hangs if they watch the timer go down.
You just have to add your timer to the main runloop as follow:
Swift 4.2
RunLoop.main.add(timer, forMode: .common)
Swift 3
RunLoop.main.add(alarm, forMode: .commonModes)
Swift 2.x
NSRunLoop.mainRunLoop().addTimer(alarm, forMode: NSRunLoopCommonModes)
I had the same problem, but in MacOS using NSOpenPanel. My problem was a timer used for TCP keep-alive which would not fire, and I would lose connection with my devices if the panel was open too long. My app would reconnect once I closed the panel, but was now in the wrong state. Just adding the code as recommended above fixed the problem.
RunLoop.main.add(timer, forMode: .common)
I am trying to show a notification window in a Mac application.Something that would come up in the trial version of the application.The window would be unmovable for 30 seconds(and it would have a counter counting down to 0).After 30 seconds it would continue execution.
Here is the code.
_systemNotificationWindow = [[SystemNotificationWindow alloc]initWithWindowNibName:#"SystemNotificationWindow"];
NSLog(#"1111");
[self.systemNotificationWindow setActionDelegate:self];
[self.systemNotificationWindow startTimer:30];
NSLog(#"2222");
[self.systemNotificationWindow showWindow:self];
NSLog(#"3333");
NSLog(#"4444");
The code is stuck at this line
[self.systemNotificationWindow showWindow:self];
It shows the window but neither the timer is working nor the window is going away after 30 seconds.Alsoo 3333 and 4444 are not being printed.
It sounds like you're missing an event loop to control the timer, so I'm guessing that you're displaying the window before an event loop has been created.
You can read more about events here and run loops here.
I have a timer set on my application using html 5 and jquery. Now when I move on to different tab or I minimize my window, the timer for that few seconds stops. I do not want this. And again as I open the window(tab or browser page, whatever u say)the timer starts. But it gets pause for those seconds. What should be the issue ? What code should I write for it ?
I want that even though I minimize my window or look at new tab, my timer should be on.
Code for getting the timer is:
Here the timer is set and it runs, but as soon as i move my focus to other page, the timer is paused. A function is just shown here.
function showTime()
{
if(ms>=100){
ms = 0;
s++;
}
// calculates seconds and hours also
var temp= $("#clock").text(checkTime(h)+":"+checkTime(m)+":"+checkTime(s)+"."+checkTime(ms));
if(windows_focus=true){
timer=setTimeout('showTime()', 10);}
else if(windows_focus=false){
timer=setTimeout('showTime()', 100);
}
}
checktime is a function which just add a zero in front of numbers<10.
I just added in windows_focus=false also, as I thought if I move away, then also it should work, but i am not getting.
I tried using setInterval also, when I use setInterval, then even though I minimize the window the timer is getting started. But the problem is that the time runs in a really weird manner. Runs very very fast.
Can anyone please help me out.
http://jsfiddle.net/JWxS6/44/ this might be useful to see my code.
I am really new, please help me out
I'm making an app for OS X 10.7 and later that plays video. Any document can be taken full-screen using the standard full-screen commands.
I'd like to forestall the automatic screen dim and display sleep as long as any document in my app is playing.
Ideally, the end (or pausing) of all playing videos should commence the full display sleep timer—a 3-minute display sleep delay shouldn't run out 1 minute and 37 seconds after the last video ends simply because something was checking or disrupting the timer every 3 minutes.
I also don't want to disable display sleep outright. If my program crashes or is force quit or the power goes out, the user's display sleep settings should remain untouched.
What's the best way to ensure that playback is not considered “idle”, but that once playback finishes, display sleep after idle works correctly?
Take a power assertion during playback with IOPMAssertionCreateWithName(), and release it when done. Power assertions handle unexpected process termination correctly:
Assertions should be released with IOPMAssertionRelease. However, even if not properly released, assertions will be automatically released when the process exits, dies, or crashes. A crashed process will not prevent idle sleep indefinitely.