locked
WriteableBitmap crashes background tasks. RRS feed

  • Question

  • I'm attempting to create custom tile images, but when I instantiate a WriteableBitmap within my BackgroundTask it crashes. Any idea why?
    Monday, January 6, 2014 9:26 AM

Answers

  • That's because the WriteableBitmap is a UI object in task that has no UI.  I don't believe you are going to be able to do this.  What exactly are you doing that requires a WB?

    Matt Small - Microsoft Escalation Engineer - Forum Moderator
    If my reply answers your question, please mark this post as answered.

    NOTE: If I ask for code, please provide something that I can drop directly into a project and run (including XAML), or an actual application project. I'm trying to help a lot of people, so I don't have time to figure out weird snippets with undefined objects and unknown namespaces.

    Monday, January 6, 2014 2:41 PM
    Moderator
  • Thanks for the response.

    I was attempting to use WB to write a dynamic bitmap to LocalStorage and use it as a tile image. I just discovered the UI thread was required for WriteableBitmap :(

    However, I figured out how save my pixel data using the following as a guide: http://msdn.microsoft.com/en-us/library/windows/apps/jj709935.aspx


    • Marked as answer by Jarem Monday, January 6, 2014 3:22 PM
    • Edited by Jarem Monday, January 6, 2014 3:37 PM
    Monday, January 6, 2014 3:22 PM

All replies

  • That's because the WriteableBitmap is a UI object in task that has no UI.  I don't believe you are going to be able to do this.  What exactly are you doing that requires a WB?

    Matt Small - Microsoft Escalation Engineer - Forum Moderator
    If my reply answers your question, please mark this post as answered.

    NOTE: If I ask for code, please provide something that I can drop directly into a project and run (including XAML), or an actual application project. I'm trying to help a lot of people, so I don't have time to figure out weird snippets with undefined objects and unknown namespaces.

    Monday, January 6, 2014 2:41 PM
    Moderator
  • Thanks for the response.

    I was attempting to use WB to write a dynamic bitmap to LocalStorage and use it as a tile image. I just discovered the UI thread was required for WriteableBitmap :(

    However, I figured out how save my pixel data using the following as a guide: http://msdn.microsoft.com/en-us/library/windows/apps/jj709935.aspx


    • Marked as answer by Jarem Monday, January 6, 2014 3:22 PM
    • Edited by Jarem Monday, January 6, 2014 3:37 PM
    Monday, January 6, 2014 3:22 PM
  • You can use Deployment.Current.Dispatcher.BeginInvoke in a background task to call an Action or a Delegate that does all the work with a WriteableBitmap.
    Tuesday, January 14, 2014 5:42 AM