×

Discussion Board

Page 1 of 2 12 LastLast
Results 1 to 15 of 16
  1. #1
    Registered User
    Join Date
    Mar 2013
    Posts
    15

    Dynamic Live Tile issue WP8 [WriteableBitmap]

    Hi,

    I want to dynamically change the live tile (drawings and custom writing) for my app in background agent every 30 minutes so I used WriteableBitmap the one that recommended for creating new image my main problem is the following
    my background agent always throw memory limits exception as using WriteableBitmap is always create large memory portion that resides during my process of drawing remaining element so background agent never fired , this problem never happened with WP7 as I used to draw only one live tile but when developing for WP8 I'm required to draw both wide tile and origin and both take a lot of memory while initializing object of WriteableBitmap

    Thanks in advance

  2. #2
    Nokia Developer Champion
    Join Date
    Sep 2012
    Location
    Morocco
    Posts
    295

    Re: Dynamic Live Tile issue WP8 [WriteableBitmap]

    How about doing one at a time,
    generate the Medium Tile get the image and store it in memory, clear the WriteableBitmap and do the same again for the Wide One, then update your tile.

  3. #3
    Registered User
    Join Date
    Mar 2013
    Posts
    15

    Re: Dynamic Live Tile issue WP8 [WriteableBitmap]

    I can't find way to clear it or finalize the object when I searched I found memory leak in the implementation of WriteableBitmap so it resides waiting for GC to collect !!

  4. #4
    Nokia Developer Champion
    Join Date
    Sep 2012
    Location
    Morocco
    Posts
    295

    Re: Dynamic Live Tile issue WP8 [WriteableBitmap]

    you can force the GC collection
    Code:
    GC.Collect();
    GC.WaitForPendingFinalizers();

  5. #5
    Registered User
    Join Date
    Mar 2013
    Posts
    15

    Re: Dynamic Live Tile issue WP8 [WriteableBitmap]

    Still have issue with it it doesn't completely removed from heap memory

  6. #6
    Registered User
    Join Date
    Feb 2007
    Location
    Tampere
    Posts
    370

    Re: Dynamic Live Tile issue WP8 [WriteableBitmap]

    I am not sure WriteableBitmap is supported for windows 8. Atleast documentation does not claim it to be supported.

    Regards
    Regards

    - MVP
    "Dare To Dream" - A.P.J.Kalam

  7. #7
    Registered User
    Join Date
    Mar 2013
    Posts
    15

    Re: Dynamic Live Tile issue WP8 [WriteableBitmap]

    If So How Do I can create custom live tile image with modification to content from background agent ??

  8. #8
    Nokia Developer Moderator
    Join Date
    Feb 2011
    Location
    Portugal
    Posts
    927

    Re: Dynamic Live Tile issue WP8 [WriteableBitmap]

    Quote Originally Posted by Mohab_Tarek View Post
    Still have issue with it it doesn't completely removed from heap memory
    Out of curiosity are you using the class directly or are you using this? http://writeablebitmapex.codeplex.com/ I used this library (its basically a wrapper for the writeablebitmap) and on some test I made a couple of months ago I had no issues with memory leak. But then again I didnt tested it in detail.

  9. #9
    Registered User
    Join Date
    Mar 2013
    Posts
    15

    Re: Dynamic Live Tile issue WP8 [WriteableBitmap]

    I used native writeablebitmap but didn't use http://writeablebitmapex.codeplex.com before do you think it have a performance better than native one ?? if so I will use it

  10. #10
    Nokia Developer Champion
    Join Date
    Nov 2011
    Location
    la bouexiere, france
    Posts
    470

    Re: Dynamic Live Tile issue WP8 [WriteableBitmap]

    writeablebitmapEx interface a writeablebitmap.

    writeablebitmap WP8 doc : http://msdn.microsoft.com/en-us/libr...v=vs.105).aspx

    Why you say, you have a memory leak?
    You create a writeablebitmap with which size?

  11. #11
    Nokia Developer Moderator
    Join Date
    Feb 2011
    Location
    Portugal
    Posts
    927

    Re: Dynamic Live Tile issue WP8 [WriteableBitmap]

    Quote Originally Posted by Mohab_Tarek View Post
    I used native writeablebitmap but didn't use http://writeablebitmapex.codeplex.com before do you think it have a performance better than native one ?? if so I will use it
    You will have to test for yourself. I never used these unless for testing and try, nothing serious.

  12. #12
    Registered User
    Join Date
    Jan 2009
    Location
    Melbourne, Australia
    Posts
    2,571

    Re: Dynamic Live Tile issue WP8 [WriteableBitmap]

    Moving from WP7 (173 x 173) to WP8 (691x336 + 336x336 + 159x159) is about 12x the amount of pixel data. If you're not being efficient with your code then obviously any problems are far more likely to show up. Unfortunately there is no way to debug this without code.

    I suggest you have a close look at your running code, perhaps with the aid of memory analysis tools: http://www.developer.nokia.com/Commu..._Windows_Phone . Start by just creating the minimum and seeing what it is that actually breaks everything. There are useful topics in the optimisation category which might help too.

    In addition, provide (buildable) code sample so that people here can debug more effectively.

    (Thanks to Vaughan Knight for advice on this)

  13. #13
    Registered User
    Join Date
    Mar 2013
    Posts
    15

    Re: Dynamic Live Tile issue WP8 [WriteableBitmap]

    Quote Originally Posted by hamishwillee View Post
    Moving from WP7 (173 x 173) to WP8 (691x336 + 336x336 + 159x159) is about 12x the amount of pixel data. If you're not being efficient with your code then obviously any problems are far more likely to show up. Unfortunately there is no way to debug this without code.

    I suggest you have a close look at your running code, perhaps with the aid of memory analysis tools: http://www.developer.nokia.com/Commu..._Windows_Phone . Start by just creating the minimum and seeing what it is that actually breaks everything. There are useful topics in the optimisation category which might help too.

    In addition, provide (buildable) code sample so that people here can debug more effectively.

    (Thanks to Vaughan Knight for advice on this)
    Thanks for reply This my complete section of code that responsible for updating live tile

    Code:
            protected override async void  OnInvoke(ScheduledTask task)
            {
         
              if (DeviceNetworkInformation.IsNetworkAvailable) //Replace this with winRT API
              {
                 
                  tileHelper = new TileHelper();
                  _settingsService = new AppSettings();
                  rateTriggerService = new RateTriggeringService();
                  rateTrigger = new RateTrigger();
                  exchangeRate = new ExchangeRate();
                  _exchangeRateService = new OnLineExchangeRates(exchangeRatesURL);
    
                 
                  var countryName = _settingsService.GetValueOrDefault<string>("Country", "United Arab Emirates");
                  IList<ExchangeRate> list = await _exchangeRateService.GetExchangeRates(Utilities.GetCountryCode(countryName).ToLower());
    
                
                  rateTrigger = await rateTriggerService.LoadAsync();
    
                  string selectedCurrency = rateTrigger.Currency;
    
                 
                  foreach (ExchangeRate item in list)
                  {
                      if (item.Currency == selectedCurrency)
                      {
                          exchangeRate = item;
                          break;
                      }
                  }
    
                  if (exchangeRate != null)
                  {
                      Deployment.Current.Dispatcher.BeginInvoke(() =>
                          {
                              UpdateTile(exchangeRate, DateTime.Now);
    
                          });
                  }
              }
              
            
        
            }
    
    
            public void UpdateTile(ExchangeRate item, DateTime lastUpdateDate)
            {
                if (item == null)
                    return;
    
                //Create medium image & wait until opened
    
    
                _medImage = new BitmapImage(new Uri("Assets/Tiles/TileBackgroundMedium.png", UriKind.Relative));
                _medImage.CreateOptions = BitmapCreateOptions.IgnoreImageCache;
    
                EventHandler<RoutedEventArgs> MedImageOpenedHandler = null;
                MedImageOpenedHandler = (s, e) =>
                {
                    _medImage.ImageOpened -= MedImageOpenedHandler;
    
                    //Create wide image & wait until opened
    
                    _wideImage = new BitmapImage(new Uri("Assets/Tiles/TileBackgroundLarge.png", UriKind.Relative));
                    _wideImage.CreateOptions = BitmapCreateOptions.IgnoreImageCache;
    
                    EventHandler<RoutedEventArgs> WideImageOpenedHandler = null;
                    WideImageOpenedHandler = (s1, e1) =>
                    {
                        _wideImage.ImageOpened -= WideImageOpenedHandler;
                        UpdateTileImages(item, lastUpdateDate);
                    };
    
                    _wideImage.ImageOpened += WideImageOpenedHandler;
    
                };
    
                _medImage.ImageOpened += MedImageOpenedHandler;
    
    
            }
    
            private async void UpdateTileImages(ExchangeRate item, DateTime lastUpdateDate)
            {
                //1. Medium tile
                var medImage = new Image { Source = _medImage };
                var medBmp = new WriteableBitmap(336, 336);//Medium tile size 
               
                medBmp.Render(medImage, null);
                
               
                //Currency
                var txtCurrency1 = new TextBlock();
                txtCurrency1.FontSize = 32;
                txtCurrency1.FontWeight = FontWeights.Bold;
                txtCurrency1.Text = item.Currency;
                txtCurrency1.Foreground = new SolidColorBrush(Colors.Black);
                medBmp.Render(txtCurrency1, new TranslateTransform() { X = 20, Y = 30 });
    
                //FC Buy
                var txtFCBuy1 = new TextBlock();
                txtFCBuy1.FontSize = 32;
                txtFCBuy1.FontWeight = FontWeights.Bold;
                txtFCBuy1.Text = "FC Buy : ";
                txtFCBuy1.Foreground = new SolidColorBrush(Colors.Black);
                medBmp.Render(txtFCBuy1, new TranslateTransform() { X = 20, Y = 100 });
    
                //FC Buy value
                var txtFCBuyValue1 = new TextBlock();
                txtFCBuyValue1.FontSize = 32;
                txtFCBuyValue1.FontWeight = FontWeights.Normal;
                txtFCBuyValue1.Text = item.FCBuy.ToString();
                txtFCBuyValue1.Foreground = new SolidColorBrush(Colors.Black);
                medBmp.Render(txtFCBuyValue1, new TranslateTransform() { X = 150, Y = 100 });
    
                //FC Sell
                var txtFCSell1 = new TextBlock();
                txtFCSell1.FontSize = 32;
                txtFCSell1.FontWeight = FontWeights.Bold;
                txtFCSell1.Text = "FC Sell : ";
                txtFCSell1.Foreground = new SolidColorBrush(Colors.Black);
                medBmp.Render(txtFCSell1, new TranslateTransform() { X = 20, Y = 150 });
    
                //FC Sell Value
                var txtFCSellValue1 = new TextBlock();
                txtFCSellValue1.FontSize = 32;
                txtFCSellValue1.FontWeight = FontWeights.Normal;
                txtFCSellValue1.Text = item.FCSell.ToString();
                txtFCSellValue1.Foreground = new SolidColorBrush(Colors.Black);
                medBmp.Render(txtFCSellValue1, new TranslateTransform() { X = 150, Y = 150 });
    
                //Last update
                var txtLastUpdate1 = new TextBlock();
                txtLastUpdate1.FontSize = 24;
                txtLastUpdate1.FontWeight = FontWeights.Normal;
                txtLastUpdate1.Text = DateTime.Now.ToString();
                txtLastUpdate1.Foreground = new SolidColorBrush(Colors.Black);
                medBmp.Render(txtLastUpdate1, new TranslateTransform() { X = 20, Y = 250 });
    
                medBmp.Invalidate();
    
               
                using (var store = IsolatedStorageFile.GetUserStoreForApplication())
                {
                    var filename = "/Shared/ShellContent/TileBackgroundMedium.jpg";
    
                    using (IsolatedStorageFile myIsolatedStorage = IsolatedStorageFile.GetUserStoreForApplication())
                    {
                        if (myIsolatedStorage.FileExists(filename))
                        {
                            myIsolatedStorage.DeleteFile(filename);
                        }
                        IsolatedStorageFileStream fileStream = myIsolatedStorage.CreateFile(filename);
    
                        medBmp.SaveJpeg(fileStream, 336, 336, 0, 100);
                        fileStream.Close();
                        fileStream.Dispose();
                    }
    
                }
    
                medBmp = null;
    
               
    
                UpdateTileData();
            }
    
            private void UpdateTileData()
            {
                if (_useMainTile)
                {
                    FlipTileData tileData = new FlipTileData()
                    {
                        BackBackgroundImage = new Uri("isostore:" + "/Shared/ShellContent/TileBackgroundMedium.jpg", UriKind.RelativeOrAbsolute),
                        //WideBackBackgroundImage = new Uri("isostore:" + "/Shared/ShellContent/TileBackgroundLarge.jpg", UriKind.RelativeOrAbsolute)
                    };
    
                    ShellTile mainTile = ShellTile.ActiveTiles.FirstOrDefault();
    
                    QueryMemory("Device Current Memory before update ");
    
                    mainTile.Update(tileData);
    
                    QueryMemory("Device Current Memory before NotifyComplete ");
    
                    NotifyComplete();
                }
                
            }

  14. #14
    Nokia Developer Expert
    Join Date
    Mar 2013
    Posts
    1

    Re: Dynamic Live Tile issue WP8 [WriteableBitmap]

    Does it happen when you update just 1 exchange rate, or when you update multiple? If it's multiple have you tried using just a single instance of WriteableBitmap which you reuse each time? This would reduce the memory footprint if it's being called multiple times, just make sure it's thread safe.

    I'll have a look at it later today, only have enough time to quickly browse the code just now.

  15. #15
    Registered User
    Join Date
    Mar 2013
    Posts
    15

    Re: Dynamic Live Tile issue WP8 [WriteableBitmap]

    Quote Originally Posted by vaughanknight View Post
    Does it happen when you update just 1 exchange rate, or when you update multiple? If it's multiple have you tried using just a single instance of WriteableBitmap which you reuse each time? This would reduce the memory footprint if it's being called multiple times, just make sure it's thread safe.

    I'll have a look at it later today, only have enough time to quickly browse the code just now.
    I only update one exchange rate when I tried to track memory usage my initialization objects take a little memory what eats memory out is initialization of WriteableBitmap image object and I can't reuse WriteableBitmap again to make another live tiles

Similar Threads

  1. Replies: 5
    Last Post: 2013-02-11, 10:54
  2. Memory usage issue during live streaming
    By jadezoole in forum [Archived] Flash Lite on Nokia Devices
    Replies: 3
    Last Post: 2009-10-20, 15:53
  3. CEikTimeEditor in dynamic form Issue
    By Shilpa13 in forum Symbian User Interface
    Replies: 4
    Last Post: 2008-12-16, 12:06
  4. dynamic array issue
    By a2sheds in forum Symbian
    Replies: 9
    Last Post: 2007-05-08, 09:34

Posting Permissions

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