locked
Are running methods resumed when app resumes? RRS feed

  • Question

  • Hello,
    I would like to know what happens when an application is resumed after suspension. Say the suspension happens while a method is running: is that method resumed after app resuming, that is, does it continue as it was not interrupted? I read in this web-page (at "App resume" section)
     http://msdn.microsoft.com/en-us/library/windows/apps/hh464925.aspx
    something that seems to confirm this scenario, but I am not sure and I would like to know further details.
    As I pointed out in another thread I am interested in unzipping/removing files operations to be completed.
    Thanks in advance
    Friday, November 22, 2013 8:50 AM

Answers

  • Hi,

    You can add a breakpoint in the code:

    private void DeleteButton_Click(object sender, RoutedEventArgs e)
            {
                Button button = sender as Button;
                string tag = button.Tag.ToString();
                int i=0;
                new System.Threading.ManualResetEvent(false).WaitOne(50000);
                string tt="5656";//Add breakpoin in this line
                           
            }

    And also add a breakpint in the App.cs OnSuspending event:

     private void OnSuspending(object sender, SuspendingEventArgs e)
            {
                var deferral = e.SuspendingOperation.GetDeferral();
                //add beakpint in this line
                deferral.Complete();
            }

    I use wait() method in order to come back to VS to check the suspend. If I do not add the method, I do not have enough time come back to VS to debug.

    If you come back to VS and suspend the app, you will find the app run the "string tt="5656" ” firstly and then run the OnSuspending event. So the app will suspend

    after the click method finished.



    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey. Thanks<br/> MSDN Community Support<br/> <br/> Please remember to &quot;Mark as Answer&quot; the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.



    • Edited by Anne Jing Friday, November 29, 2013 5:54 AM edit
    • Marked as answer by P5music Wednesday, December 4, 2013 9:45 PM
    Friday, November 29, 2013 5:52 AM

All replies

  • When a app is resumed it will not continue to run a method that was running when the app suspended. 
    Friday, November 22, 2013 11:25 AM
  • Hi,

    You cannot suspend an app when you running a
    method. You can test it in your VS. I create a click button event and make the
    thread sleep like below:

     private void DeleteButton_Click(object sender, RoutedEventArgs e)
            {
                Button button = sender as Button;
                string tag = button.Tag.ToString();
                int i=0;
                new System.Threading.ManualResetEvent(false).WaitOne(50000);
    
                           
            }

    When click the button and go back to VS to click
    the suspend button, you will find you cannot suspend the app because the click
    event is running.

    Best Wishes!



    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey. Thanks<br/> MSDN Community Support<br/> <br/> Please remember to &quot;Mark as Answer&quot; the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.


    • Edited by Anne Jing Thursday, November 28, 2013 7:37 AM edit
    Thursday, November 28, 2013 7:37 AM
  • thanks Anne Jing,

    but are you sure this behaviour is not due to the singularity of the wait() method or VS capabilities? What happens if it's the system that try to suspend a method that is normally running (i.e. unzipping an archive) with no call to methods like wait() or similar? Is this intended to be a workaround?

    Thursday, November 28, 2013 10:03 AM
  • Hi,

    You can add a breakpoint in the code:

    private void DeleteButton_Click(object sender, RoutedEventArgs e)
            {
                Button button = sender as Button;
                string tag = button.Tag.ToString();
                int i=0;
                new System.Threading.ManualResetEvent(false).WaitOne(50000);
                string tt="5656";//Add breakpoin in this line
                           
            }

    And also add a breakpint in the App.cs OnSuspending event:

     private void OnSuspending(object sender, SuspendingEventArgs e)
            {
                var deferral = e.SuspendingOperation.GetDeferral();
                //add beakpint in this line
                deferral.Complete();
            }

    I use wait() method in order to come back to VS to check the suspend. If I do not add the method, I do not have enough time come back to VS to debug.

    If you come back to VS and suspend the app, you will find the app run the "string tt="5656" ” firstly and then run the OnSuspending event. So the app will suspend

    after the click method finished.



    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey. Thanks<br/> MSDN Community Support<br/> <br/> Please remember to &quot;Mark as Answer&quot; the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.



    • Edited by Anne Jing Friday, November 29, 2013 5:54 AM edit
    • Marked as answer by P5music Wednesday, December 4, 2013 9:45 PM
    Friday, November 29, 2013 5:52 AM
  • Thanks,
    It's encouraging.
    I tried also with no WaitOne() call and no breakpoint, calling from the Button_Click() method an external method performing an infinite loop (with Debug.WriteLine("going on") inside) and bringing also another app to foreground. The suspension doesn't happen.
    I hope this is a legitimate developing technique so to be able to implement it in my app when it comes to unzipping an archive or removing files from a directory. I think yes because, probably, memory will not be over on common cases, so my app will not be likely to get closed. However I would like to know more about this.
    • Edited by P5music Saturday, November 30, 2013 1:00 PM
    Saturday, November 30, 2013 12:18 PM