locked
Maintaining data/variable

    Question

  • Hi,

    i'm working on windows runtime component that will be consumed by a javascript app. I've a few questions;

    1) Everytime the JS app call a function in WinRT component, do some process and when it return to js, every data stored in that function variables will be lost. Is this correct?

    2) If q1 is correct, how do I make the data/variables always available for a single session? let say, during app startup, it should call the WinRT component, do some process and stored data(s) in a vector. From there on, data from that vector should always be accessible until the app is suspended/closed.

    Thanks.

    Thursday, April 18, 2013 8:34 AM

Answers

  • I'm not entirely clear what you're trying to accomplish, but it sounds like a classic example of variable scope definition. If your function call is acting on variables that need to be accessed outside of the scope of the function then these variables need to be declare as static or allocated on the heap. Any variable declared in the function and allocated on the stack would only be accessible within the scope of the function.
    • Proposed as answer by Jesse Jiang Monday, April 22, 2013 5:34 AM
    • Marked as answer by Jesse Jiang Tuesday, April 23, 2013 5:46 AM
    Thursday, April 18, 2013 2:35 PM
  • Yes, please take a look of this document and there are the sample codes in that document
    http://msdn.microsoft.com/en-us/library/windows/apps/xaml/hh779077.aspx

    Best regards,
    Jesse


    Jesse Jiang
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Marked as answer by Jesse Jiang Tuesday, April 23, 2013 5:46 AM
    Monday, April 22, 2013 5:34 AM

All replies

  • I'm not entirely clear what you're trying to accomplish, but it sounds like a classic example of variable scope definition. If your function call is acting on variables that need to be accessed outside of the scope of the function then these variables need to be declare as static or allocated on the heap. Any variable declared in the function and allocated on the stack would only be accessible within the scope of the function.
    • Proposed as answer by Jesse Jiang Monday, April 22, 2013 5:34 AM
    • Marked as answer by Jesse Jiang Tuesday, April 23, 2013 5:46 AM
    Thursday, April 18, 2013 2:35 PM
  • If variables are declared as static, then the JS app should be able to retrieve values from those variables at any time, right?

    Thanks.

    Friday, April 19, 2013 12:50 AM
  • Yes, please take a look of this document and there are the sample codes in that document
    http://msdn.microsoft.com/en-us/library/windows/apps/xaml/hh779077.aspx

    Best regards,
    Jesse


    Jesse Jiang
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Marked as answer by Jesse Jiang Tuesday, April 23, 2013 5:46 AM
    Monday, April 22, 2013 5:34 AM