Created
August 19, 2011 05:57
-
-
Save csainty/1156149 to your computer and use it in GitHub Desktop.
blog post - Background Agents
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class ScheduledAgent : ScheduledTaskAgent | |
{ | |
protected override void OnInvoke(ScheduledTask task) { | |
if (task is PeriodicTask) { | |
// Do quick processing | |
} else { | |
// Do long processing | |
} | |
NotifyComplete(); // or Abort(); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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