Question

When I try to add a periodic task in windows phone 7.5 it gives me a "BNS Error: The maximum number of ScheduledActions of this type have already been added." error while i haven't added any periodic task. The code works fine on Windows phone 8 but raises this error on WP7.5. Also the app schedules reminders and alarms.

string periodicTaskName = "myperiodictask";
        PeriodicTask periodicTask = ScheduledActionService.Find(periodicTaskName) as PeriodicTask;
        if (periodicTask != null)
        {
            try
            {
                ScheduledActionService.Remove(periodicTaskName);
            }
            catch (Exception)
            { }
        }
        periodicTask = new PeriodicTask(periodicTaskName);
        periodicTask.Description = "Updates LiveTile, Sessions and Assignments";
        periodicTask.ExpirationTime = DateTime.Now.AddDays(10);
        try
        {
            ScheduledActionService.Add(periodicTask);
        }
        catch (InvalidOperationException exception)
        {
            if (exception.Message.Contains("BNS Error: The action is disabled"))
                MessageBox.Show("Background agents have been disabled by the user.");
            if (exception.Message.Contains("BNS Error: The maximum number of ScheduledActions of this type have already been added."))
                MessageBox.Show("maximum number of ScheduledActions of this type have already been added!");
        }
        catch (SchedulerServiceException)
        { }
Was it helpful?

Solution

How are you testing the background agent? Emulator or Device. Either way, you need to make sure you're not testing on a low memory 'device'.

On low memory devices (256mb), background agents are disabled. Unfortunately, the error thrown is the same as when the maximum number of agents are scheduled, i.e. "BNS Error: The maximum number of ScheduledActions of this type have already been added."

OTHER TIPS

Please refer these posts.

http://codeblog.vurdalakov.net/2012/02/solution-bns-error-maximum-number-of.html

http://imjo.hn/2013/01/23/bns-error-the-maximum-number-of-scheduledactions-of-this-type-have-already-been-added/

In debugging you added some task and its registered your app but you are not removing earlier tasks thats why this happening.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top