locked
Drawing in a separate thread RRS feed

  • Question

  • Hi,

    This is what I'm trying to accomplish (Windows 8 Store App using C# and XAML):

    1. Fill out Canvas with some elements.

    2. Spawn a new thread.

    3. Animate the elements in Canvas in the thread. Should I use an infinite loop to do that?

    4. Terminate the thread when the user presses a button.

    The biggest question for me is how to spawn a new thread with an infinite loop in it and at the same time to be responsive to UI.

    Any suggestions?

    Thanks,

    Leszek


    Wiki: wbswiki.com
    Website: www.wisenheimerbrainstorm.com


    • Edited by ata6502 Wednesday, November 13, 2013 3:33 AM
    Wednesday, November 13, 2013 3:31 AM

Answers

  • Hi,

    it is not a good idea to create a new thread to move your objects because they ar bound to the ui thread. If you would try to manipulate the positon of a element inside the canvas from an other thread, you would have to dispatch back to your ui thread. If I get you right, you try to implement a "gameloop" so you could Loop a Storyboard or  use a timer for this, or use CompositionTarget.Rendering for what you are trying to do. A imho good Silverlight example can be found here:

    http://blogs.msdn.com/b/nikola/archive/2009/08/19/exposed-5-methods-to-create-game-loop-which-is-the-best.aspx

    Not all Version will work with winrt, but the CompositionTarget.Rendering is  imho the way to go.


    lh

    • Marked as answer by ata6502 Thursday, November 14, 2013 2:42 AM
    Wednesday, November 13, 2013 9:04 PM

All replies

  • Hi,

    it is not a good idea to create a new thread to move your objects because they ar bound to the ui thread. If you would try to manipulate the positon of a element inside the canvas from an other thread, you would have to dispatch back to your ui thread. If I get you right, you try to implement a "gameloop" so you could Loop a Storyboard or  use a timer for this, or use CompositionTarget.Rendering for what you are trying to do. A imho good Silverlight example can be found here:

    http://blogs.msdn.com/b/nikola/archive/2009/08/19/exposed-5-methods-to-create-game-loop-which-is-the-best.aspx

    Not all Version will work with winrt, but the CompositionTarget.Rendering is  imho the way to go.


    lh

    • Marked as answer by ata6502 Thursday, November 14, 2013 2:42 AM
    Wednesday, November 13, 2013 9:04 PM
  • Thanks Lars. CompositionTarget.Rendering  is what I was looking for.

    Leszek


    Wiki: wbswiki.com
    Website: www.wisenheimerbrainstorm.com

    Thursday, November 14, 2013 2:42 AM