Keep agent active in windows phone - windows-phone-7

I want a service to be active always in the background. Is this possible in the new SDK 7.1
I read through the Background File Transfers, Agents, and Alarms. I think these are only active for a period of time.

Short answer: you can't
Background agents can only run for 15 seconds every ~30 minutes. Attempting to run for longer will result in the agent being terminated and not rescheduled. Riho is referring to something different: if the user does not run the owner application for 14 days your agent won't be rescheduled (even if it's successful); the application must be run and reschedule the agent.
Your only real choice is to move the functionality to the server and use push notifications to update the phone.

Agent gets deactivated after 14 days. Within that time you must make user to open your foreground application - then you can restart the agent and 14 days counter again.

Related

Will Heroku dyno automatic restarts kill running processing on my application?

I have an application that is hosted on Heroku. The application has a process that is run on the server, that the user has the ability to start and stop. Once the user clicks 'Start', the process is supposed to stay running until the user presses 'Stop'. The functionality of the app should allow that the process can be run for extended periods of times (6 months or so) continuously.
I have deployed my app on a Heroku free dyno. While reading the Heroku documentation, I came across this page that states that Heroku Dynos are restarted automatically every 24 hours. Here is the relevant passage:
Dynos are also restarted (cycled) at least once per day to help maintain the health of applications running on Heroku. Any changes to the local filesystem will be deleted. The cycling happens once every 24 hours (plus up to 216 random minutes, to prevent every dyno for an application from restarting at the same time). Manual restarts (heroku ps:restart) and releases (deploys or changing config vars) will reset this 24 hour period. Cycling happens for all dynos, including one-off dynos, so dynos will run for a maximum of 24 hours + 216 minutes. If you have multiple dynos, they should cycle at different times based on the random 0 to 216 minutes difference. If you continually make changes to your application without a 24 hour gap, you won’t see cycling at all.
Does this mean that the user process that he/she has started will automatically be stopped when the dyno restarts? If yes, does it automatically resume the user process where it left off?
If not, I will have to find a different hosting solution since the process may need to be run 24x7x365.
Does this mean that the user process that he/she has started will automatically be stopped when the dyno restarts?
Yes it does. As it will when you change config variables, or deploy updates, or add / remove addons.
If yes, does it automatically resume the user process where it left off?
No it doesn't. Any safe-and-resume behaviour you have to implement in your application. When stopping processes, Heroku will send them a SIGTERM signal and give them 30 seconds to safe their work.
If not, I will have to find a different hosting solution since the process may need to be run 24x7x365.
I doubt that there is any hosting solution that will give you what you want. In a cloud environment restarts are a thing that happens all the time, at least for you updating your application, bugfixes, security fixes. Every hosting provider or platform that provides you with 24x7x365 uptime will also restart and replace your dynos all the time.

Azure cloud service app (web role) goes down for ~10 mins occasionally due to Windows Updates? How can I schedule them?

It seems to happen every couple months or so and while it auto-recovers on its own usually within ~10 minutes I'd still like to find out how to change the Windows Update schedule since it frequently occurs during business hours.
We have several web apps in various Azure subscriptions, and they all behave this way. Once we get a notification that one goes down, the others usually go down over the next few days/week.
I used remote desktop to view the Event Viewer for the web role and see the following (this down time took place between 9:48am and 10:02am on the east coast, so definitely not ideal):
8/6/2020 1:48:15 PM - "Automatic Updates is now paused."
Followed by several services stopping, and then:
8/6/2020 1:52:53 PM - "The process C:\43..61\Setup.exe (RD..33) has initiated the restart of computer RD..3 on behalf of user NT AUTHORITY\SYSTEM for the following reason: Other (Planned)
Reason Code: 0x80000000
Shutdown Type: restart
Comment: "
8/6/2020 1:52:53 PM - "Automatic Updates is now resumed."
8/6/2020 1:53:10 PM - "The operating system is shutting down at system time ‎2020‎-‎08‎-‎06T13:53:10.614704600Z."
8/6/2020 1:53:12 PM - The operating system started at system time ‎2020‎-‎08‎-‎06T13:53:12.487679900Z.
Obviously it takes a while for everything to come back up, and I finally get notified that the site is back up about 9 minutes later.
Is there a way to specify when the Windows Updates should take place?
I can tell you clearly that it is not possible to schedule windows updates.
The windows update in this cloud services is about once a month. The time is not fixed. There is no way to control this.
Azure Guest OS releases and SDK compatibility matrix
solution:
We can create 2 webroles so that we can solve the situation that the program is closed due to windows update.
principle:
Create 2 webroles to load balance the server pressure. When the windows is updated, it will not be updated at the same time, but a planned instance update ends, and the next instance update is performed.
In this way, as long as you create >=2 webrols, there will be 2 instances, so that the program can guarantee that it will not stop due to updates.

Using Scheduled Task Agent with Periodic Task local notification at a particular time in WP8

Using Scheduled Task Agent with Periodic Task in Windows Phone 8 how do i show the local notification at a particular time. For example at (9AM and 5 PM) every day?
You can't as it's impossible to schedule it for any specific time frame. From the MSDN documentation:
Periodic agents typically run every 30 minutes. To optimize battery life, periodic agents may be run in alignment with other background processes and therefore the execution time may drift by up to 10 minutes.
Other options available if you need that level of precision are
1) Programmatically set a reminder for the specific time that you want.
2) Push notifications from an external service to subscribed devices at your specified interval. Bear in mind that Push notifications delivery is slightly unreliable on windows phone.

Running Windows phone 7 app in background

I want a part(Service) in my windows phone app to run periodically.Actually its a server request , which should be made periodically and show any changes to user as notification
You should use the PeriodicTask which runs every 30 minutes in the background unless the user has not forbidden that. Notify the user about changes with a ShellToast or think about Push Notifications.
Important: Please keep in mind, that you can never rely on background tasks in Windows Phone. There are many reasons why such a task will not run. So do not outsource necessary or important work to it.

Is there a hard limit on how long Azure role startup can take?

Suppose I include a rather long-running startup task into my Azure role - running something like up to several minutes. What happens if the startup task runs "too long".
I'm currently testing on Compute Emulator and observe the following.
I have a 450 megabytes .zip file together with Info-Zip unzip. The startup task unzips the archive. Deployment starts and I look into Task Manager. Numerous service processes start, then unzip.exe is run. After about two minutes all those processes stop and then start anew and unzip.exe starts again.
So it looks like a deployment is allowed to run for about two minutes, then is forcefully reset and started again.
Is this the expected behavior? Does it persist on real cloud? Are there any hard limits on how long a role startup can take? How do I address this situation except moving the unpacking into RoleEntryPoint.OnStart()?
I had the same question, so tried an experiment. I ran a Startup Task - taskType="simple" so that it would block the Roles from beginning to execute - and let it run for 50 hours. The Fabric Controller did not complain and the portal did not show any error. It finished its long "do nothing" loop after the 50 hours was up, then this Startup Task exited, and my Web Role started up fine.
So my emperical test says Startup Tasks can take a long time! At least 50 hours.
This should inform the load balancer that your process is still busy:
http://msdn.microsoft.com/en-us/library/microsoft.windowsazure.serviceruntime.roleinstancestatuscheckeventargs.setbusy.aspx
I have run startup tasks that run for a pretty long time (think 20-30 mins) and the role is simply in a 'Busy' state. I don't think there is a hard limit for how long the role will stay in that state as long as the Startup task is still executing and did not exit with a non-zero return code (in fact, this is a gotcha for most first time startup task creators when they pop a prompt). The FC is technically still running just fine, so there would be no reason to 'recover' the role (i.e. heartbeats are still going).
The dev emulator just notices when the role hasn't started and warns you. If you click the 'keep waiting' option, it will continue to run the Startup task to completion. The cloud does not do this of course (warn you).
Never tried a task that ran super long, so there might be a very long limit. I seem to recall 3 hrs was a magic number in some timeout cases like role recycles, but I have never tried...
There are some heartbeats that the Azure Fabric Agent will do against the role. If these are not acknowledged (say a long-running blocking process), this could cause the role to be flagged as unavailable.
You might try putting your startup process into a background thread that runs independently. This should help you keep the role from being recycled while the process is starting up. Just keep in mind you may need to make some adjustments if you get requests before the role fully starts up. There's also a way (that I can't seem to recall ATM) to flag the role and take it out of the load balancer temporarially while your process completes.

Resources