Augusto Accorsi
Augusto Accorsi

Reputation: 327

Resuming and suspendig WinRT Camera App

I have an app with three pages: MainPage, Page2 and Page3. At MainPage I have my camera, at Page2 I have the historical with the scans from MainPage, and my Page3 has some infos about the app. My issue is when I Suspend and when I Resume it. It suspends ok, but when I press the resume button at Visual Studio LifeStyle Events I get the following error A remote operation is taken longer then expected. As you can see, my app is taking to much time to be resumed.

At my App.xaml.cs I have this OnSuspending method:

public App()
{
    this.InitializeComponent();
    this.Suspending += this.OnSuspending;
}

private void OnSuspending(object sender, SuspendingEventArgs e)
{
    var deferral = e.SuspendingOperation.GetDeferral();
     deferral.Complete();
}

And in my MainPage I have this Resuming Method:

public MainPage()
{
    this.InitializeComponent();
    Application.Current.Resuming += App_resuming;
}

async void App_resuming(object sender, object 
{
    if (Frame.Content == this)
    await InitializeCamera();
}

I think I have to dispose my camera when I suspend the app, so I created an Suspend Method at MainPage also, where I dispose my camera

void App_suspending(object sender, Windows.ApplicationModel.SuspendingEventArgs e)
{
   _mediaCapture.Dispose();
}

So, just reformulating my question: What am I doing is right? What am I missing? Thanks.

Upvotes: 0

Views: 256

Answers (1)

Nishi
Nishi

Reputation: 614

I could reproduce your problem when i am not disposing camera object on suspend, which you said you have tried but still its taking longer time. What i can suggest you to check camera object if it really getting dispose. To make sure you can add below lines of code in OnSuspend:

await cameraCapture.StopPreview();
cameraCapture.Dispose();
cameraCapture = null;

and in resume before initializing camera, create object again.

Upvotes: 1

Related Questions