×

Discussion Board

Page 2 of 2 FirstFirst 12
Results 16 to 26 of 26
  1. #16
    Nokia Developer Champion
    Join Date
    Nov 2011
    Location
    la bouexiere, france
    Posts
    475

    Re: Problem with ScheduledTaskAgent, RestSharp and WriteableBitmap

    i miss this point.

  2. #17
    Registered User
    Join Date
    Mar 2013
    Posts
    14

    Re: Problem with ScheduledTaskAgent, RestSharp and WriteableBitmap

    I think the problem is the HTTP Get + Deserialization of Data + Rendering.... If i try running either Get + Deserialization + Native Tile update it works.... And it also works if i only run Tile update without HTTP Get + Deserialization....

  3. #18
    Nokia Developer Champion
    Join Date
    Nov 2011
    Location
    la bouexiere, france
    Posts
    475

    Re: Problem with ScheduledTaskAgent, RestSharp and WriteableBitmap

    What is the update frequency you want use?

  4. #19
    Nokia Developer Moderator
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    28,745

    Re: Problem with ScheduledTaskAgent, RestSharp and WriteableBitmap

    If you are already into testing these combinations, it may make sense checking their execution time.

  5. #20
    Registered User
    Join Date
    Mar 2013
    Posts
    14

    Re: Problem with ScheduledTaskAgent, RestSharp and WriteableBitmap

    Quote Originally Posted by yan_ View Post
    What is the update frequency you want use?
    It should update when the scheduled agents run, i.e. around every 30 minutes, as it happened in the previous version...

  6. #21
    Nokia Developer Champion
    Join Date
    Nov 2011
    Location
    la bouexiere, france
    Posts
    475

    Re: Problem with ScheduledTaskAgent, RestSharp and WriteableBitmap

    ok. So you can do it in two times.
    have you try to save your tiles in jpeg ?

  7. #22
    Registered User
    Join Date
    Mar 2013
    Posts
    14

    Re: Problem with ScheduledTaskAgent, RestSharp and WriteableBitmap

    I finally made it!
    What i had to do:
    1) Create a Core class for some of my referenced solutions
    2) clean up all unused Assmblies
    3) Save to jpeg and not png
    4) Most important: resort to saving the data to DB AFTER tile generation and after a good GC collect

    Thanks everyone for the help!

  8. #23
    Registered User
    Join Date
    Feb 2013
    Posts
    2

    Question Re: Problem with ScheduledTaskAgent, RestSharp and WriteableBitmap

    Quote Originally Posted by Iacopo View Post
    I finally made it!
    What i had to do:
    1) Create a Core class for some of my referenced solutions
    2) clean up all unused Assmblies
    3) Save to jpeg and not png
    4) Most important: resort to saving the data to DB AFTER tile generation and after a good GC collect

    Thanks everyone for the help!

    Hi Iacopo,

    Would you mind telling me more about how you did 4)? I am facing a similar issue as my app's wide tile generation throws me with an OutOfMemory exception on WP7.8 while it works fine on WP8. I also store the image in jpeg format.

    Many thanks!
    Justin

  9. #24
    Nokia Developer Champion
    Join Date
    Mar 2013
    Posts
    520

    Re: Problem with ScheduledTaskAgent, RestSharp and WriteableBitmap

    WP7.8 allows less memory for the PeriodicUpdateAgents than WP8 does. As for allowing the GC to collect no longer used objects. You have to ensure that everything you no longer need currently isn't referenced in any way by running code. e.g.:

    Code:
    var x = hugeObject;
    doSomething(hugeObject);
    x = null;//remove reference to hugeObject
    
    GC.Collect();//would run by itself before an OOM occurs but you can give a hint to the Garbage Collector
    
    doSomethingElse();
    You have to make sure that there are NO references to the object that is no longer needed. If you don't set the reference to null it will stay alive until the method referencing it has returned (at which point the reference will be removed when the heap is cleaned up).

  10. #25
    Registered User
    Join Date
    Feb 2013
    Posts
    2

    Question Re: Problem with ScheduledTaskAgent, RestSharp and WriteableBitmap

    Quote Originally Posted by SB Dev View Post
    WP7.8 allows less memory for the PeriodicUpdateAgents than WP8 does. As for allowing the GC to collect no longer used objects. You have to ensure that everything you no longer need currently isn't referenced in any way by running code. e.g.:

    Code:
    var x = hugeObject;
    doSomething(hugeObject);
    x = null;//remove reference to hugeObject
    
    GC.Collect();//would run by itself before an OOM occurs but you can give a hint to the Garbage Collector
    
    doSomethingElse();
    You have to make sure that there are NO references to the object that is no longer needed. If you don't set the reference to null it will stay alive until the method referencing it has returned (at which point the reference will be removed when the heap is cleaned up).
    Thanks for the reply!

    I just tried this but it doesn't seem to reduce the memory use. Did I do something wrong?

    Here is my code in the background agent class.

    Code:
            protected override void OnInvoke(ScheduledTask task)
            {
                // dunno why but it starts with almost 5MB of memory...
                var shellTile = ShellTile.ActiveTiles.FirstOrDefault();
    
                // get the ShellTile type so we can call the new version of "Update" that takes the new Tile templates.
                Type shellTileType = Type.GetType("Microsoft.Phone.Shell.ShellTile, Microsoft.Phone");
    
                if (shellTile == null)
                    return;
    
                var data = new LiveTileData();
    
                // GetData uses about 3MB of memory, it either gets the data from a web service or get it from Isolated storage
                LiveTileDataManager.Current.GetData(data, () =>
                {
                    CustomTile customTile;
                    UIElement frontTileTemplate, backTileTemplate, smallFrontTileTemplate, wideFrontTileTemplate, wideBackTileTemplate;
    
                    frontTileTemplate = new FrontTileTemplate
                    {
                        Property1 = data.Property1
                    };
    
                    backTileTemplate = new BackTileTemplate()
                    {
                        Property1 = data.Property1
                    };
    
                    smallFrontTileTemplate = new SmallFrontTileTemplate()
                    {
                        Property1 = data.Property1
                    };
    
                    wideFrontTileTemplate = new WideFrontTileTemplate()
                    {
                        Property1 = data.Property1
                    };
    
                    wideBackTileTemplate = new WideBackTileTemplate()
                    {
                        Property1 = data.Property1
                    };
    
                    // free up memory here???
                    data = null;
                    GC.Collect();
    
                    // pass in the small, normal & wide front tiles
                    customTile = CustomTile.GetTemplatedTile(frontTileTemplate, backTileTemplate, smallFrontTileTemplate, wideFrontTileTemplate, wideBackTileTemplate);
    
                    // this functions uses about 2MB of memory, it basically saves all tiles as JPEGs to isolated storage
                    var flipTileData = customTile.GetFlipTileData();
    
                    // free up memory here???
                    customTile = null;
                    frontTileTemplate = null;
                    backTileTemplate = null;
                    smallFrontTileTemplate = null;
                    wideFrontTileTemplate = null;
                    wideBackTileTemplate = null;
                    GC.Collect();
    
                    // invoke the new version of ShellTile.Update.
                    shellTileType.GetMethod("Update").Invoke(shellTile, new Object[] { flipTileData });
    
                    // tell the scheduled agent to complete
                    this.NotifyComplete();
                });
            }

  11. #26
    Registered User
    Join Date
    Mar 2013
    Posts
    14

    Re: Problem with ScheduledTaskAgent, RestSharp and WriteableBitmap

    For calling the GC, try using the following, which allows waiting for resources to be released:
    Code:
    GC.Collect();
    GC.WaitForPendingFinalizers();
    GC.Collect();
    In my case, though, the most important thing was to clean up all the assemblies used, together with making a smaller version of a referenced class inside my project.... Did you try and add Toast in various points of the code, to see exactly where the background agent is killed?

Similar Threads

  1. Dynamic Live Tile issue WP8 [WriteableBitmap]
    By Mohab_Tarek in forum Windows Phone General
    Replies: 15
    Last Post: 2013-03-14, 22:17

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×