Skip to content

Instantly share code, notes, and snippets.

@csainty
Created August 19, 2011 05:57
Show Gist options
  • Save csainty/1156149 to your computer and use it in GitHub Desktop.
Save csainty/1156149 to your computer and use it in GitHub Desktop.
blog post - Background Agents
if (((double)DeviceStatus.ApplicationCurrentMemoryUsage / (double)DeviceStatus.ApplicationMemoryUsageLimit) * 100d > 97d) {
// We are using too much memory, try clean a few things up
if (_Ctx != null)
_Ctx.Dispose();
_Ctx = new gReadieModelContext(gReadieModelContext.ConnectionString);
GC.Collect();
if (((double)DeviceStatus.ApplicationCurrentMemoryUsage / (double)DeviceStatus.ApplicationMemoryUsageLimit) * 100d > 97d) {
// We couldn't recover enough memory, so we are really running out, lets be nice and bail
NotifyComplete();
return;
}
}
public class ScheduledAgent : ScheduledTaskAgent
{
protected override void OnInvoke(ScheduledTask task) {
if (task is PeriodicTask) {
// Do quick processing
} else {
// Do long processing
}
NotifyComplete(); // or Abort();
}
}
<Tasks>
<DefaultTask Name="_default" NavigationPage="Home.xaml" />
<ExtendedTask Name="BackgroundTask">
<BackgroundServiceAgent Specifier="ScheduledTaskAgent" Name="gReadie.BackgroundAgent" Source="gReadie.BackgroundAgent" Type="gReadie.BackgroundAgent.ScheduledAgent" />
</ExtendedTask>
</Tasks>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment