Repeat a task with time delay in WinJS - gps

I am developing an app in WinJS and I need to periodically run some tasks with a constant and specified delay between each pair of executions.
In particular, I am intending to update the user's position on the map every 30 seconds.
I am not quite sure how to implement the task scheduler in WinJS. I have looked at the background task class, but that doesn't seem to be much help in my case.

If Im reading this correctly and you simply want to do this while the application is running you just need a javascript timer - setTimeout.
note that with setTimeout you pass in the function itself without parenthesis, not a string name. Here's an app sample with a timer that updated the UI, although the main important takeaway here is that you need to make sure you call setTimeout again from within your 'update' function. Check out that code here
If you want some sort of background task to do this and generate a separate image (I dont think thats what you ant, but I'll include that since we're talking about tasks and delays)
If you are using Windows 8.1 (which releases soon) you can use the new scheduler class and pause and resume every 30 seconds as shown here
If you are using Windows 8 (and will work on 8.1) you can if I recall correctly setup your scheduled tasks every fifteen minutes and create one shot tasks for each 30 seconds within that time. run background task on timer

Related

vb.net console in a do loop

I've written a fairly simple console app to check an Exchange email box every 30 seconds. When it's not running the check routine, it's in an empty do/loop in the Main method just to keep the program running. I find that that is taking a whole lot more of the server's resources (around 50%) than I expected.
Here's the Main method:
Sub Main()
GetSettings()
tmrCheckInterval.Interval = 30000
tmrCheckInterval.Start()
WriteToConsole("Scan app started")
Do
Loop
End Sub
I don't do very many console apps, so I am not sure if this is the most efficient way, and I have struck out with a Google search. Is there an alternative process that will keep the app running without consuming resources?
Thanks...
If you only want this to run every 30 minutes, you are much better off removing the loop entirely and instead setting up a Scheduled Task.
But as to why this code uses so much CPU... the program is doing work. It has a tight loop that never stops and never yields the CPU. It sits near 50% because you have a dual-core CPU and this uses all of one core. If you had a quad-core, it would use 25%. In the bad old single core days, this would use all of the CPU and even bringing up the task manager to kill the app could be challenging. I'm gonna have nightmares tonight remembering those times, so thanks for that.
I know it seems like you set an interval in this code, but that interval only applies to the timer, and is not part of the loop body. You want something more like this:
Sub Main()
GetSettings()
WriteToConsole("Scan app started")
Do
'Remove the timer and call it's elapsed code directly here.
Thread.Sleep(30 * 60 * 1000)
Loop
End Sub
And again, this is still not as good as just using a scheduled task.

How to stop the user moving the console window in vb.net

I'm currently taking computer science A-Level so it should be obvious how to do this as I have been using VB.Net for a year already. However, I have developed a console application which uses the threading.thread.sleep() function to keep track of timings. This is so far the best way I have found to do so but after some destructive testing I have found when the user drags the console around quickly this slows the program down and causes the timings to be wrong. So, is there any way to stop the user from moving a console window, essentially keeping the location of the console fixed, in vb.Net? I'm currently using Visual Studio 2015.
Many Thanks,
Dan
Although it may be possible to stop the window being dragged, it is the wrong approach. Sleeping a thread is not an accurate way of maintaining timing data.
Moving the window is not the only action on a windows system that will slow the application down and you're beginning to interfere with the standard windows experience.
I assume you have code that increments the amount of delay after each sleep.
Instead: To maintain accuracy you should store the value of DateTime.Now when the application starts timing.
dim mStartTime = DateTime.Now
And then get the time differences relative to this.
dim elapsedMilliseconds = (DateTime.Now - mStartTime).TotalMilliseconds
All timers / sleep rountines are subject to timing error due to system priority / loads. This approach will prevent those errors accumulating.
Modifying the console is not easy from .net (you need to use the windows api), however it's pretty simple to prevent the user from doing this if you're using winforms. Maybe you could change your application type.

Running a block of code in the background of AppleScriptObjC app?

Is it possible to have a block of code constantly running or 'repeating' in AppleScriptObjC, whilst the rest of your script is still active? I've got a block of code that I want to repeat in the background that checks to see if a folder exists and creates it if it doesn't, but if I set it to repeat indefinitely then I lose the ability to access the other buttons and code blocks in my app?
Apologies if there isn't enough info here or it's a bit confusing!
I'd probably create a repeating NSTimer to do the check at a specified interval. That would avoid blocking your main thread.
Depending on the app, perhaps you could also just check for the existence of the folder and create it just in time, when you really have a need for it.

Run same code after install application

My app before first run need execute same code. Is possible move this to installer?
No. iOS apps are installed with Apple's App Store installation process. Apple does not offer any hooks into the installation process to inject code. The app will have to execute this first run code at first run.
If this first run work is significant, and you want to move the work to the install process because it blocks the UI during first run, you can do some things to alleviate the problem. First, you can put this code on its own thread, and let the main thread start the UI. You can then jump to asking for the user to enter settings, or go through help screens explaining the program. While the user is working through these tasks with low computing resource demands, the higher demand setup thread may have plenty of time to do the first run work.

App launch sequencer

Every morning when I get into work I launch about a dozen apps and whatnot (FF, TB, VSx2-3, Eclipse, SSH, SVN update x2-3). Needles to say this does a good job of warming up my HDD for the day. I rather suspect that it would run a lot faster if they were launched sequentially (not to mention that I wouldn't need to click in 17 different places).
Is there a preexisting product that can kick off a sequence of tasks/apps/etc. where each task is only started after the last app is done hammering the HDD?
It would nerd to be able to kick apps like VS and firefox and also be able to trigger explorer context menu items like SVN update in TortoiseSVN.
Try SlickRun, it's free, I've used it for years, I use it constantly and I'd be lost without it.
Think of it like a configurable Start->Run command, it'll do what you want (you can configure n second pauses between multiple commands), and if you install it you'll use it for a thousand different things before the first week is out.
P.S. I have no stake in SlickRun, I just like it :)
Unfortunately, I don't know of any software that can do this for you automatically.
However, can't you trigger the updates through a console SVN task? If so, can't this be done by creating a batch file? It's low tech, and you might want to add a few pauses between each task, but it should do what you want.
As you mention TortoiseSVN, I'll assume your O/S is windows.
You could launch an Autohotkey script at startup. I don't think it can easily detect HDD activity, but you can at least wait until each window appears with the WinWaitActive command.
If each application has an average time they take to complete, you could simply use Windows' Scheduled Tasks application. Obviously you'll need to be running Windows but Scheduled Tasks can be found in the Control Panel.
Execute "Add Schedules Task", select the program, the frequency and then the specific time.