Run task in background to check every hour

I am using Long Running Task (background) to get updates every hour. The app needs to check the scheduler settings to enable or disable services in the app. The problem is that I can only run the Long Running Background for 3 minutes and I need that running all the time.

`public async Task Start ()
{
CancellationTokenSource cancelToken = new CancellationTokenSource ();

nint taskId = UIApplication.SharedApplication.BeginBackgroundTask ("LongRunningTask", OnExpiration);

try 
{
    await DoWork(cancelToken.Token);
} 
catch (Exception) 
{
} 
finally 
{
    if (cancelToken.IsCancellationRequested) 
    {
        NotificationHelper.SendLocalAlertNotification ("iBeacon Test App", "Scheduler Task Cancelled");

        var log = new BeaconLog(){
            Status = "SchedulerTaskCancelled"
        };
        loggingService.WriteLog(log);
        System.Diagnostics.Debug.WriteLine("Scheduler Task Cancelled");
    }
}

UIApplication.SharedApplication.EndBackgroundTask (taskId);

}
`

Any ideas? Am I doing something wrong?

Sign In or Register to comment.